Question

Around my image processing software I use exiftool to successfully shuffle around exif info from Cr2, TIFF, JPG files. The added tags, such as "keywords", are all visible in OSX (mountain lion) Finder, Preview and nicely indexed by Spotlight.

For PNGs I need to fallback to XMP as this is the metadata container for PNG. However, exiftool-added tags do not seem to be picked up by neither Preview nor SpotLight. In contrast, if I first add a tag in Preview and use exiftool to add a new tag later, this IS indexed. The difference here I see here in the XMP raw data, where exiftool newly creates a header, while Preview does not.

As an example, look at the following PNG from the Wikipedia page on PNG without metadata https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png:

Sample PNG without metadata

Adding a keyword using exiftool, and afterwards dumping the XMP datablock:

exiftool -xmp-dc:subject=ViaExifSubject ./PNG_transparency_demonstration_1.png
exiftool -xmp -b ./PNG_transparency_demonstration_1.png

Gives the following XMP data:

<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 9.02'>
    <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
 <rdf:Description rdf:about=''
  xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <dc:subject>
   <rdf:Bag>
    <rdf:li>ViaExifSubject</rdf:li>
   </rdf:Bag>
  </dc:subject>
 </rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='r'?>

However, in Preview or Finder info panel, no "ViaExifSubject" is found.

Alternatively, using OSX Preview to add comments (Open in Preview, Show Inspector, Go to Keywords tab, click '+' to add keyword). XMP dumped again via exiftool:

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.1.2">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:dc="http://purl.org/dc/elements/1.1/">
         <dc:subject>
            <rdf:Bag>
               <rdf:li>viaPreview</rdf:li>
            </rdf:Bag>
         </dc:subject>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>

The xpacket header is not present in Preview generated keyword, and the XMP Toolkit is different. The "viaPreview" tag is visible now, e.g. using mdls on the CLI.

Pushing raw XMP info into a clean file also doesn't give the expected result:

exiftool "-xmp<=viaexif.xmp" PNG_transparency_demonstration_1.png

Surprisingly, if I first create a tag using Preview and THEN do the command above, the new tags are reflected I suspect that I am overseeing an external data parser that needs to be 'activated', picks up the tags and puts them in a different store (e.g. .DS_store). I have not seen any xattr being added.

These are my questions:

  • Is exiftool the right tool for XMP/PNG combination, and am I missing a specific feature
  • Is OSX defying an XMP standard? Edit: apparently XMP is not respected by OSX per default
  • Should I investigate in an alternative tool to strip the container ?

I dug up my xmp_sdk on my disk and experimented with the provided samples:

ModifyXMP can write "pure" XMP info into PNG which is shown in OSX Finder -- this is a good target.

ReadingXMP can read XMP info inserted by ExifTool into PNG, although this info is not shown in OSX Finder.

The file size is similar when looking at ModifyXMP's output and exiftool inserting the exact same XMP blob. A diff shows that exiftool appends at the end of the file where XMP sdk puts it in the header of the PNG. The XMP spec states that "Encoders are encouraged to place the chunk at the beginning of the file, but this is not required."

Conclusion: There is a (slight) difference in how exiftool writes XMP and this specifically messes with OSXs metadata retrieval.

For now:

  • Experiment with XMP SDK instead to insert a clean XMP packet at the beginning, and have exiftool reuse this first chunk.
  • I reposted on exiftools' forum, and author Phil Harvey replied:

    I did some playing with Apple Preview, and not only does it not recognize XMP at the end of the file, but also it deletes this XMP when adding keywords to the image. My guess is that Apple software ignores XMP if it comes after the IDAT chunk. It would have been wonderful if the XMP specification had mandated that the XMP chunk come before IDAT, but it didn't, so this must be considered a bug in the Apple software. I have added this to the list of Known problems.

    Finally, Phil Harvey decided to fix this problem in Exiftool itself:

    I have done a lot of work on this, and Exiftool 9.40 will have a new option to allow you to write XMP before the PNG IDAT chunk. The corresponding command will look like this: exiftool -api PNGEarlyXMP ...

  • Filed a bug at Apple -- Update dec 2014: Apple closed my bug stating that they will not take any action on this topic

Was it helpful?

Solution

  1. You try XMP Toolkit SDK and its samples and write metadata for PNG.
  2. OSX uses IPTC (not sure, read somewhere) and XMP toolkit does reconcile XMP and IPTC, therefore the keyword added using XMP Toolkit will be searchable on OS X.

From your observation it looks like exiftool doesn't reconcile IPTC and XMP. What you could try is to try and change both IPTC and XMP inside PNG and see if it is searchable.

OTHER TIPS

Preview.app now works just fine with

exiftool -xmp-dc:subject=ViaExifSubject 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top