Image Format Normalization

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
h1d3m3
Posts: 8
Joined: 2009-07-27T13:48:16-07:00
Authentication code: 8675309

Image Format Normalization

Post by h1d3m3 »

Our application processes 10s of thousands of user uploaded images daily (mostly from cameras). Our "happy path" when processing these images is to go into javax.imageio.ImageIO to see if the image is readable/sane. If it fails, we go to ImageMagick to covert it to PNG or JPEG and resize or set the colorspace if needed. Most of the time, if the image initially fails ImageIO, ImageMagick produces an image that then *can* be read by java's ImageIO, but not always. We do see a set of images that Java chokes on even after ImageMagick has read / converted; meaning ImageMagick is awesome (and more forgiving) and Java ImageIO is kinda lame (and stricter). For example, ImageMagick had no errors with this image during the conversion/resizing process, but java still chokes with ImageMagick's results:
java.awt.color.CMMException: Invalid image format
at sun.awt.color.CMM.checkStatus(CMM.java:131)
at sun.awt.color.ICC_Transform.<init>(ICC_Transform.java:89)
at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:516)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1169)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1137)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:948)
at javax.imageio.ImageReader.read(ImageReader.java:923)
This is just one example and I'm not trying to solve this specific exception. I'm interested to know if there is a general way to strip out all of the "abnormal" metadata / garbage from an image so that it is as "plain jane" as possible. The convert -strip option looks promising. At the end of the day, the more cruft we can remove from an image, but still preserve the important aspects of the image format, the better.

Any advice welcome.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image Format Normalization

Post by fmw42 »

-strip will remove profiles and other meta data. I believe it also strips exif data and such as well (but not certain of that). I don't know of any other IM function to remove more. There may be other non-IM solutions specific to JPG or PNG. Or perhaps something like exiftool. There are also some specific PNG optimizers.

see the sections on JPG and PNG at http://www.imagemagick.org/Usage/formats/
Post Reply