macosexifspotlightxmpexiftool

Exiftool to create OSX visible XMP metadata in PNG images


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:


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:


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.