I've been working on an ImageIO plugin for reading JPEGs for a while. One of the features I'd like to implement, is automatic rotating of the image, according to EXIF/TIFF Orientation tag, if present.
I'm not asking how to implement the rotation itself, rather my issue is with the ImageReader API. For many users, simply calling ImageIO.read(myJPEG)
is all they ever do, and I think thery're happy with having the image rotated to the correct orientation. However, if you look at the ImageReader
API, it has many methods to get information and metadata about the image, and also various ways to read the pixel data.
Should I expose a way to read the data as is in the file, using ImageReadParam
(I could do it the other way around too, but that would not allow the common case mentioned above to have the benefit of the functionality)?
I'm working on metadata support (as in IIOMetadata
), should the metadata report the orientation tag as written in the file, or updated to reflect the rotated image? This is where I feel things break down... The real issue here, is what happens when someone reads the image and metadata, does some manipulations to the image and stores it again with the metadata (should the writer then do the oposite rotation, or 'magically' discard the orientation tag and update w/h)?
...or optionally, should I just give it up, and leave it to clients to read the EXIF metadata, and apply the rotation themselves if needed?
Input and suggestions from implementors as well as ImageIO users are welcome! :-)
Reasons why not to rotate the image
Reasons why to rotate the image
I think ImageIO should rotate the image and update the Exif. That way the developer can work with ImageIO without worrying about the image file format. And the behaviour of the new JPEGReader is compatible with the old one.
Additional features would be
I think we should leave the past behind (Exif not beeing standard) and consider the orientation in Exif to be part of JPEG. But I think we still should ignore all the other Exif information when putting pixels into memory or on the screen ;-)
Given that every image reader in the World automagically flips the image correctly, I'm betting that virtually everybody would be fine with this happening automatically. In a sense, the image "is" the it's rotated version even if the bitmap portion of the image file says different. The whole file is the standard.
And yes, I'd be very happy if ImageIO.read() would just, um, work. It should give me an image that is as it would be displayed by every known viewer on the planet. Sure, include some APIs to get at it the raw way if somebody really wants that, but the default behavior should be the prevailing usage pattern, and the way that makes sense. Why would you ever have a need to view it in the wrong orientation? There might be odd use cases, but I bet they are very rare compared to the normal one.
Any idea when they are going to fix this in the default JDK? Writing my own code to do my own rotation to put the image back felt sick and wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With