Image Format Normalization
Posted: 2010-11-04T13:24:11-07:00
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:
Any advice welcome.
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.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)
Any advice welcome.