I'm working on a photo viewer. In this context, I wrote a small class to be able to read and use some EXIF data, as e.g. image orientation. This class works well for reading.
However, I want to add a new option to rotate photos. I want to rotate and write the photo data itself, not just rewrite the orientation tag. I already wrote the code to rotate and save the primary JPEG image, and it works well. But I also need to rotate the thumbnail contained in the EXIF data, if any, to keep the image coherent. For this reason I need to write in the EXIF data, to replace the existing thumbnail.
But this raises some questions, that I've some trouble answering, namely:
- Can the EXIF data contain more than 1 thumbnail, and if yes, what is the maximum thumbnail count that an image can contain?
- What are the supported formats for thumbnails? (I found JPEG and TIFF, are there others?)
- Is there any guarantee in the EXIF standards that the thumbnails are always written in the late EXIF data, just before the primary image?
- If not, then each tags containing an offset that points to a location beyond the thumbnail to replace should be updated. So, is there a standard way to iterate through all tags and sub-directories, to recognize which EXIF tags contain offsets, and to update them if needed? Or is the only way to read a number maximum of tags and rewrite only the ones that are known?
- Or is there a way to guarantee that the size of the newly rotated thumbnail will be smaller or equal to previous thumbnail size to replace with?