Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!)

share|improve this question
    
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

4 Answers 4

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.

share|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

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()
share|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

I found the perfect tool for what I needed, this blog post covers it in greater detail.

Searches recursively through a directory and finds any corrupted JPEGS. Looks like you can use as many cores as you like to search too.

Here's a screenshot that shows it in action.

Screenshot of Corrupt JPEG Checker

share|improve this answer
    
Yes, I have that. It is one of the tools I have included in a batch-file to run a battery of tests on a given file or directory. Sadly, like pretty much all of the others, it is only for JPGs. I have yet to find a tool that can accurately test GIFs or PNGs (or BMPs). ☹ –  Synetech Apr 3 '13 at 21:18

This can be done by using the Python Imaging Library's .verify() command.[1]

To run this in Windows, install Python (I installed the current latest release of Python 2), and then install Pillow (a fork of Python Imaging Library (PIL)). Then, copy the code of jpeg_corrupt.py[2] and save its contents to a .PY file, e.g. jpeg_corrupt.py.

Note that I changed the following line of code in jpeg_corrupt.py:
self.globs = ['*.jpg', '*.jpe', '*.jpeg']
to
self.globs = ['*.jpg', '*.jpe', '*.jpeg', '*.png', '*.gif']
This so .PNG and .GIF files will be scanned too.

It can then be executed through the Windows command prompt (cmd.exe) like this: C:\Python27\python.exe "C:\Directory containing the .PY file\jpeg_corrupt.py" "C:\Directory of folder to be scanned"

The first part of the command, 'C:\Python27\python.exe', might be different depending on which version of Python you installed and which directory you installed it to. In my example, it is the default installation directory of Python 2.7.

It should scan all JPG, GIF and PNG images in the specified directory and all of its subdirectories. It will show an output if it detects a corrupted image file.

I ran this on OP's sample image and it gave this error message: ...\YcB9n.png: string index out of range.

The code could also be entered in a .BAT script file, so you can easily run it a specified directory without needing to use the command prompt:

C:\Python27\python.exe "C:\Directory containing the .PY file\jpeg_corrupt.py" "%CD%"
pause



Sources:

[1]: Answer in Stack Overflow - "How do I programmatically check whether an image (PNG, JPEG, or GIF) is corrupted?" by ChristopheD
[2]: Comment by Denilson Sá in the SO answer linked in [1]

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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