I recently developed a Java Servlet running on Tomcat7 that is supposed to accept POST of pictures from different formats (PNG, JPG, BMP). And perform the following tasks:
- Scale them down if greater than 2000px
- Cache other dimensions (if allowed)
- Run a hashing algorithm to identify similar images
- Store and cache them all as JPG
As fastest solution I rely on ImageIO that was producing a decent result before i ran into more "new" formats. There are two main issues that I can not find a working solution for:
- Progressive JPEG
- JPEG that includes EXIF metadata
I evaluated different solutions but none of them seems to solve both solutions (i will list best two):
- Apache Imaging (read EXIF, can not read/write JPEG, it is slow)
- JMagick (accept JPEG & Progressive JPEG, do not care about EXIF)
Has anyone of you been able to implement a solution that works with both formats?
You could try im4java which also uses ImageMagick under the hood like JMagick. But instead of being a wrapper for the native libraries it uses the command line to communicate with ImageMagick.
ImageMagick has the operation
-auto-orientwhich converts the image to the "correct" orientation automatically. For detailed information take a look at the documentation.Advantages
Disadvantages
Maven Dependency
Example 1 (with files)
Example 2 (with input/output streams)
Example 3 (image information)
Performance
You can also take a look at this question for performance optimizations (but beware that there was a
-colorspace rgband an unnecessary, because not supported for JPEG images,-coalesceoperation which both increased the processing time).Documentation
Here you can find the developers's guide with more examples.