2

我正在使用commons io成像庫將xmp元數據添加到JPEG文件。這是我如何做它:從commons io成像寫入的XMP數據不可讀元數據提取器

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

上述文件運行exiftool顯示從上面創建的XMP數據:

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

但是,使用metadata-extractor我無法讀取從Description標籤以上:

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()); 
    } 
} 

更有趣的是,metadata-extractorCAN讀取0123當exiftool被用於創建XMP標籤

$ 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()); 
    } 
} 
+0

僅供參考,此問題來自問題https://github.com/drewnoakes/metadata-extractor/issues/200 –

回答

0

元數據提取器標籤產生用於錯誤(第二「自粘標籤」)你連接到這個問題圖像:

ERROR: Error processing XMP data: XML parsing failure

進一步看,似乎XMP XML只包含以下內容:

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

在您發佈的代碼的第一線,很明顯這是爲什麼。

這不是有效的XMP文檔。 Adobe的XMPCore庫不接受它。

您可能希望使用XMPCore庫生成有效的XMP文檔。或者,添加相關的父標籤。