Write image metadata after processing.
Now that implemented image scaling, the processed images currently don't contain metadata. We need to put appropriate metadata in the output files. To large extent this will be the reverse process of GUISE-148.
This implementation writes all the metadata collected from in addition to the following:
Exif software: Software (0x0131)
Exif modification timestamp: DateTime (0x0132), SubSecTime (0x9290), OffsetTime (0x9010)
Exif ColorSpace (0xA001) value of 1 to indicate sRGB.
As hoped, discarding all metadata and then rewriting a tiny bit of Exif metadata dropped the file size down significantly:
1920 Quality 0.8 original metadata
1920 Quality 0.6 original metadata
1920 Quality 0.8 rewritten metadata
1920 Quality 0.6 rewritten metadata
An answer to Safely discarding ICC profile information in Java Image I/O implies that it might be a good idea to set the Exif ColorSpace (0xA001) tag to 1 to indicate sRGB if we've converted it and removed all other metadata. Also Jeffrey Friedl's blog entry Digital-Image Color Spaces, Page 7: Recommendations and Links has these "Suggestions for the Software Developer" (bold added):
The makes of browsers, image-display applications, image editors, and image-printing applications would do well to...
Recognize and apply embedded color profiles.
If an image has no profile, but is tagged as sRGB with the EXIF:ColorSpace tag, use sRGB. All digital cameras that I know of write sRGB color data without an embedded color profile, but they do note sRGB in this Exif field.
If no profile and no ColorSpace field, respond to the InteroperabilityIndex field (“R98” for sRGB, “R03” for AdobeRGB). This is from an Exif-related extension to JEITA's DCF (“Design rule for Camera File system”) standard.
If all else fails, use a default color space that is initially sRGB, but allow the user to change it to whatever color space they like.
Educate your users about color-space issues.
Furthermore, software that writes images....
When the color space is sRGB, include the sRGB profile and set the following Exif tags:
ColorSpace = 1;
InteroperabilityIndex = 'R98';
InteroperabilityVersion = '0100';
So let's add the ColorSpace (0xA001) tag set to sRGB for good measure.
Very tricky: DateTime goes in IFD0, while SubSecTime and OffsetTime go in the SubIFD.
The Exif 2.32 spec is saying in Annex E.3.3 0th IFD Table 56 that if I update the metadata, besides setting the software (which I do already) that I should set what they call DateTime (0x0132), referred to in some places as ModifyDate. And accordingly it looks like there is a corresponding OffsetTime (0x9010). There is even a SubSecTime (0x9290).
Although dropping the resolution and lowering the quality will result in smaller file sizes, it seems a shame to wind up with a file size 50KB to 70KB larger than necessary—and from an answer to Safely discarding ICC profile information in Java Image I/O it indeed seems I can safely discard the metadata in this case, including the ICC profile metadata, as the processing apparently converts the image to sRGB anyway. And I found out how to write the createdAt information to Exif using Apache Commons Imaging.
So I'm reopening this ticket to strip all the metadata out of even the primary image, and write back just the necessary metadata (which now from is quite useful and reasonably complete). I'll move createdAt writing back to this ticket and close as a duplicate.