Page 1 of 1

Finding faulty PNGs

PostPosted: 15 Jan 2021, 03:19
by Wuzzy
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?

Re: Finding faulty PNGs

PostPosted: 15 Jan 2021, 10:55
by GunChleoc

Re: Finding faulty PNGs

PostPosted: 15 Jan 2021, 21:28
by CYBERDEViL
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

Re: Finding faulty PNGs

PostPosted: 15 Jan 2021, 23:40
by Wuzzy
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.

Re: Finding faulty PNGs

PostPosted: 16 Jan 2021, 16:20
by CYBERDEViL
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.