Finding faulty PNGs

Finding faulty PNGs

Postby Wuzzy » 15 Jan 2021, 03:19

I often have the problem that faulty PNGs sneak into my game files, triggering libpng warnings. However, I have a lot of PNG and I know some of them are faulty (usually incorrect sRGB profile). But I don't know which of my lots and lots of PNGs are faulty.

Here's my question to you:
Given a large directory containing many PNGs of which a few are faulty, how do I locate the faulty PNGs?
User avatar
Wuzzy
 
Posts: 989
Joined: 28 May 2012, 23:13

Re: Finding faulty PNGs

Postby GunChleoc » 15 Jan 2021, 10:55

User avatar
GunChleoc
 
Posts: 502
Joined: 20 Sep 2012, 22:45

Re: Finding faulty PNGs

Postby CYBERDEViL » 15 Jan 2021, 21:28

Could be as simple as this

{l Code}: {l Select All Code}
#!/bin/bash

shopt -s nullglob
for file in ./*.png; do
   identify "$file" > /dev/null 2>&1
   if [ "$?" -ne "0" ]; then
      echo "File $file is corrupt."
   fi
done
User avatar
CYBERDEViL
 
Posts: 22
Joined: 23 Jan 2020, 22:22

Re: Finding faulty PNGs

Postby Wuzzy » 15 Jan 2021, 23:40

Ah, thanks. I didn't know that the identify program gives an useful return code for faulty PNGs. That's nice. :)

ImageMagick is pretty daunting, to be honest, there's so much you must read. xD But it's also pretty awesome.
User avatar
Wuzzy
 
Posts: 989
Joined: 28 May 2012, 23:13

Re: Finding faulty PNGs

Postby CYBERDEViL » 16 Jan 2021, 16:20

Wuzzy {l Wrote}:Ah, thanks. I didn't know that the identify program gives an useful return code for faulty PNGs. That's nice. :)

ImageMagick is pretty daunting, to be honest, there's so much you must read. xD But it's also pretty awesome.


Yeah almost always enough to read :-P IBut 've made a mistake, you might want to add the `-regard-warnings` flag to the identify command for it to be more strict.
User avatar
CYBERDEViL
 
Posts: 22
Joined: 23 Jan 2020, 22:22

Who is online

Users browsing this forum: No registered users and 1 guest

cron