Write image metadata after processing.

Description

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.

Environment

None

Activity

Show:
Garret Wilson
February 20, 2021, 3:49 PM
Edited

As hoped, discarding all metadata and then rewriting a tiny bit of Exif metadata dropped the file size down significantly:

Image

1920 Quality 0.8 original metadata

1920 Quality 0.6 original metadata

1920 Quality 0.8 rewritten metadata

1920 Quality 0.6 rewritten metadata

ad3-1089.jpg

215KB

156KB

177KB

119KB

am4-3213.jpg

533KB

392KB

475KB

334KB

ashd1-7696.jpg

272KB

193KB

235KB

155KB

IMG_0525.jpg

347KB

239B

232KB

149KB

IMG_0743.jpg

379KB

263KB

323KB

211KB

IMG_3527.jpg

396KB

265KB

340KB

214KB

Garret Wilson
February 18, 2021, 2:48 PM
Edited

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...

  1. Recognize and apply embedded color profiles.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

Garret Wilson
February 16, 2021, 2:47 PM

Very tricky: DateTime goes in IFD0, while SubSecTime and OffsetTime go in the SubIFD.

Garret Wilson
February 15, 2021, 10:32 PM
Edited

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).

Garret Wilson
February 15, 2021, 8:55 PM

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.

Fixed

Assignee

Garret Wilson

Reporter

Garret Wilson

Labels

None

Epic Link

Components

Fix versions

Priority

Major