Detecting corrupted images in bash script [closed]
Try ImageMagick's identify
command. From the man page:
Identify describes the format and characteristics of one or more image files. It will also report if an image is incomplete or corrupt.
Example:
$ identify foo.pngidentify: NotAPNGImageFile (foo.png).$ echo $?1
An alternative, is to use PIL (Python Imaging Library):
from PIL import Imageim = Image.open("foo.png")im.verify()
From the documentation:
im.verify()
Attempts to determine if the file is broken, without actually decoding the image data. If this method finds any problems, it raises suitable exceptions. This method only works on a newly opened image; if the image has already been loaded, the result is undefined. Also, if you need to load the image after using this method, you must reopen the image file.
I tried the ImageMagick identify
command on a jpg I had laying around with several kinds of corruptions thrown in. It was able to identify some, but not all, so this might just be a partial solution at best, but try this:
for f in *.JPG ; do identify $f > /dev/null || echo $f >> /tmp/fail ; done ; cat /tmp/fail