Does anyone know of a good program that can scan graphics files (particularly JPG, GIF, and PNG) for corruption?

Preferably, it would be able to scan a bunch of photos automatically and have some sort of manual review option as well.


Explanation:

A few days ago, a command-line command did not work correctly and ended up deleting thousands of graphics files from a FAT32 volume that was practically out of space. I’ve used several different file/photo-recovery programs, but naturally, they are limited in how much they can recover (though fortunately the volume has 8KB clusters which helps somewhat).

Anyway, some of the larger files that were fragmented, are now corrupt. Some of them are not even real files at all (the recovery software merely dumped the clusters that were pointed to by now-overwritten directory entries), while others are broken because of fragmentation.

Moreover, because some picture formats embed a smaller version of the picture as a thumbnail, scanning the thumbnails for corruption is not reliable because it may be intact while the actual file (ie, the picture when viewed full-size), could be corrupt.


Here’s a couple of examples. (The third one wouldn’t even upload because it doesn’t even have the correct header!)

link|improve this question

48% accept rate
You mean visual corruption, I assume? I'd LOVE this...finally I could stop eyeballing the thumbnails of my comic books for broken jpgs. – Shinrai Apr 27 '11 at 19:24
Visual or structural. I found one app that supposedly did this, but it missed lots of files that didn’t even have the header! – Synetech Apr 27 '11 at 19:27
Oh, that stuff didn't even occur to me. Yes, please...this has to exist SOMEWHERE right? – Shinrai Apr 27 '11 at 19:55
1  
Can you upload one or more examples of such a broken file and link to them in your question? – slhck Apr 27 '11 at 20:19
@Shinrai, examining the thumbnails is not reliable because many picture formats include a separate thumbnail version embedded in the picture, and that may be intact. That’s why sometimes a picture whose thumbnail looks fine, is corrupt when opened. – Synetech Aug 17 '11 at 0:41
show 2 more comments
feedback

2 Answers

Try the jpeginfo '-c' option for your JPEG files.

I've seen the corruption you show happen with bad memory cards too.
What you want should be possible and available, check Corruption of Graphics Files;
a section from the online Encyclopedia of Graphics File Formats.

Also see File Integrity Checks in A Basic Introduction to PNG Features.

You may be interested in this Stackoverflow question,
How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?


Update: Source tarball for version 1.6.1 by Timo Kokkonen.
You should be able to build a binary for your machine.

link|improve this answer
Unfortunately, I can’t find any Windows ports. – Synetech Apr 28 '11 at 21:22
jpeginfo is open-source; you should be able to get the tarball and compile it on your system (maybe with Cygwin that has libjpeg). – nik May 3 '11 at 15:59
It’s moot either way, because I need to scan at least GIFs and PNGs as well. – Synetech Sep 9 '11 at 0:04
feedback

ImageMagick's identify program will let you know if an image is corrupt. A 'for i in find' loop testing for a none-0 return code from identify would let you script the test pretty easily to dump a list of damaged or corrupted files. It works on Windows with PowerShell too.

enter image description here

The following code with changes for your path works well in powershell

$stream = [System.IO.StreamWriter] "corrupt_jpegs.txt" 
get-childitem "c:\" -include *.jpg -recurse | foreach ($_) { 
    & "C:\Program Files\ImageMagick-6.7.1-Q16\identify.exe" $_.fullname > $null 
    if($LastExitCode -ne 0){ 
        $stream.writeline($_.fullname) 
    } 
} 
$stream.close()
link|improve this answer
I haven’t used ImageMagick in a while (it had bugs the last time I tried), but I’ll look into it. Thanks for the suggestion. – Synetech Aug 17 '11 at 0:39
The viewer tool is still buggy, but identify worked great for me with a similar problem. I used a powershell script like this to get a list of corrupt and or 0 length image files. – OldWolf Aug 17 '11 at 18:19
@Synetech inc. Sorry, can't update the original post with formatted code since an image was posted to it and I can't seem to get this to format nicely either. Sample Powershell script: (adjust your paths, file types etc..) $stream = [System.IO.StreamWriter] "corrupt_jpegs.txt" get-childitem "c:\" -include *.jpg -recurse | foreach ($_) { & "C:\Program Files\ImageMagick-6.7.1-Q16\identify.exe" $_.fullname > $null if($LastExitCode -ne 0){ $stream.writeline($_.fullname) } } $stream.close() – OldWolf Aug 17 '11 at 18:37
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.