2

I am using commons io imaging library to add xmp metadata to a JPEG file. This is how I'm doing it:

   String xmpXml = "<dc:decription>some sample desc123</dc:description>";
   JpegXmpRewriter rewriter = new JpegXmpRewriter();
   rewriter.updateXmpXml(is,os, xmpXml);

Running exiftool on the above file shows the created xmp data from above:

$ exiftool 167_sample.jpg | grep "Description"
Description                  : some sample desc123

However, using metadata-extractor I can't read the Description tag from above:

Metadata metadata = com.drew.imaging.ImageMetadataReader.readMetadata(file.inputStream) 
for (XmpDirectory xmpDirectory : metadata.getDirectoriesOfType(XmpDirectory.class)) {
    XMPMeta xmpMeta = xmpDirectory.getXMPMeta();
    XMPIterator itr = xmpMeta.iterator();
    while (itr.hasNext()) {
        XMPPropertyInfo property = (XMPPropertyInfo) itr.next();
        System.out.println(property.getPath() + ": " + property.getValue());
    }
}

More interestingly, metadata-extractor CAN read the Description tag when exiftool is used to create the xmp tag

$ exiftool -xmp-dc:description=Manuallyaddedthis 167_sample.jpg

Metadata metadata = com.drew.imaging.ImageMetadataReader.readMetadata(new File ("167_sample.jpg")) 
for (XmpDirectory xmpDirectory : metadata.getDirectoriesOfType(XmpDirectory.class)) {
    XMPMeta xmpMeta = xmpDirectory.getXMPMeta();
    XMPIterator itr = xmpMeta.iterator();
    while (itr.hasNext()) {
        XMPPropertyInfo property = (XMPPropertyInfo) itr.next();
        System.out.println(property.getPath() + ": " + property.getValue());
    }
}
Omnipresent
  • 29,434
  • 47
  • 142
  • 186

1 Answers1

0

metadata-extractor produces an error for the (second, "self-adhesive labels") image you attached to this issue:

ERROR: Error processing XMP data: XML parsing failure

Looking further, it seems that the XMP XML contains only the following:

<dc:description>some sample description</dc:description>

In the first line of the code you posted, it's clear why.

This is not a valid XMP document. Adobe's XMPCore library isn't accepting it.

You might like to use the XMPCore library to produce a valid XMP document. Alternatively, add the relevant parent tag(s).

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742