Verifying JPEG integrity

From: Dan Lyke 
------------------------------------------------------
I'm going through and reconciling a sh*load of my old backups, and
I've had a few image files corrupted over the years.

The ones that are are usually pretty obvious, and I'm discovering some
of them when trying to run some command-line face detection tools on
them, but...

Does anyone have a favorite simple command-line "see if everything
looks legit in this jpeg" tool?

jhead and jpeginfo just look in the headers. mogrify outputs some tag
complaints for images which still look okay.

What I'd really like is something that exits with a zero code if the
image looks like it's got all of its data, and a non-zero code if it
doesn't.

Clues?

Dan

=============================================================== From: flushy@flushy.net ------------------------------------------------------ Quoting Dan Lyke : Pretty sure that in some of those corrupted states, the color bitmap is intact, but the intensity map is corrupted (which I think is later). I'm not an expect in jpeg format, but I've seen breakdowns of the format with different quality, and the lower the quality, the more "cow spot"-ish the color bitmap appears. Yet, the intensity or whatever it is that maps the colors into the pixels looks mostly the same. I'd imagine that the intensity or whatever it is map looks mostly randomized. Which is why some corrupted jpegs appear fine till half-way down, then becomes a nice mosaic pattern of rgb. Depending upon the type of corruption, I'd imagine that smooth animation or cartoons may appear "corrupted", too if you use some type of constant pattern type matching. I have two solutions in mind: (1) create a bunch of thumb nails (this is easy with ImageMagick). Then view them in a browser or table/column view where you can delete: (1.a) the ones that look good or (1.b) the ones that look bad. [1.1] finally, keep or delete the matching thumbnails with the originals, and the merged or reduced set will contain the corrupted files. (2) check for header file size, and compare to actual image length -- the difference being a rough estimate of corruption. (3) check for header file size, compare x% of end of file for all zeros, apply to file size to gain rough estimate of corruption. --b

=============================================================== From: Wil Wade ------------------------------------------------------ It looks like what you need is ... imagemagick identify -verbose image.jpg via: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=20045

=============================================================== From: Ed King ------------------------------------------------------ I just did a similar project about a year ago=0A=0Afunction jpeg

=============================================================== From: Dan Lyke ------------------------------------------------------ On Fri, 28 Feb 2014 05:47:16 -0800 (PST) Ed King wrote:

=============================================================== From: Ed King ------------------------------------------------------ I forgot to mention, if the jpeg is found to be corrupt, I used...=0A=0Ajpe= gtran -trim filename.jpg=0A=0Ato "fix" it=0A=0A=0A=0A=0A

=============================================================== From: flushy@flushy.net ------------------------------------------------------ Quoting Wil Wade : I've noticed that ImageMagick complains about jpeg files from my camera, and sometimes ffmpeg does, too. They appear fine, however to the eye. So, I had to convert the jpeg to another jpeg using ImageMagick, so get a "good clean jpeg", then pass that to ffmpeg. My point is, just because it SAYS there is something wrong with the file, doesn't mean that the file isn't viewable anyways. --b

=============================================================== From: Dan Lyke ------------------------------------------------------ Yeah, there are a few tools that complain about things like weird EXIF tags or similar, but work just fine. Ed's method probably finds all the ones that I'm really worried about, I'm about to run some Perl to see which ones I've got that look corrupt. Dan