'Python XMP Toolkit: Remove ` lang="x-repair" ` from image description
Summary:
I am trying to set the description of an image file using XMP metadata, with the Python XMP Toolkit (libxmp). I figured out how to do this, but for some reason, the string lang="x-repair" always precedes the description in certain programs. I'm an XMP noob, but I think it's due to the <rdf:li xml:lang="x-repair"> tag being interpreted incorrectly by the viewing/editing software. I need to find a workaround.
Problem Example:
Initial XMP (before adding description):
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Exempi + XMP Core 5.6.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
<xmpMM:OriginalDocumentID>B4C00FF319085C77E5CD0403E55E459E</xmpMM:OriginalDocumentID>
<xmpMM:DocumentID>xmp.did:7E6929740E3811EAA465CD5529117D4E</xmpMM:DocumentID>
<xmpMM:InstanceID>xmp.iid:7E6929730E3811EAA465CD5529117D4E</xmpMM:InstanceID>
<xmpMM:DerivedFrom rdf:parseType="Resource">
<stRef:instanceID>xmp.iid:ab5c3c17-673a-4472-a464-5e81f92ba608</stRef:instanceID>
<stRef:documentID>B4C00FF319085C77E5CD0403E55E459E</stRef:documentID>
</xmpMM:DerivedFrom>
<xmp:CreatorTool>Adobe Photoshop CS5 Windows</xmp:CreatorTool>
<photoshop:AuthorsPosition>Contributor</photoshop:AuthorsPosition>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
Then I run the following to add a description:
my_image.xmp.append_array_item(libxmp.consts.XMP_NS_DC, "description", "This is a test.", {"prop_array_is_alt":True})
Now python says this is my current XMP:
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Exempi + XMP Core 5.6.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<xmpMM:OriginalDocumentID>B4C00FF319085C77E5CD0403E55E459E</xmpMM:OriginalDocumentID>
<xmpMM:DocumentID>xmp.did:7E6929740E3811EAA465CD5529117D4E</xmpMM:DocumentID>
<xmpMM:InstanceID>xmp.iid:7E6929730E3811EAA465CD5529117D4E</xmpMM:InstanceID>
<xmpMM:DerivedFrom rdf:parseType="Resource">
<stRef:instanceID>xmp.iid:ab5c3c17-673a-4472-a464-5e81f92ba608</stRef:instanceID>
<stRef:documentID>B4C00FF319085C77E5CD0403E55E459E</stRef:documentID>
</xmpMM:DerivedFrom>
<xmp:CreatorTool>Adobe Photoshop CS5 Windows</xmp:CreatorTool>
<photoshop:AuthorsPosition>Contributor</photoshop:AuthorsPosition>
<dc:description>
<rdf:Alt>
<rdf:li>This is a test.</rdf:li>
</rdf:Alt>
</dc:description>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
BUT! Once I close the file (write XMP) and open it again, it says this is my XMP:
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Exempi + XMP Core 5.6.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<xmpMM:OriginalDocumentID>B4C00FF319085C77E5CD0403E55E459E</xmpMM:OriginalDocumentID>
<xmpMM:DocumentID>xmp.did:7E6929740E3811EAA465CD5529117D4E</xmpMM:DocumentID>
<xmpMM:InstanceID>xmp.iid:7E6929730E3811EAA465CD5529117D4E</xmpMM:InstanceID>
<xmpMM:DerivedFrom rdf:parseType="Resource">
<stRef:instanceID>xmp.iid:ab5c3c17-673a-4472-a464-5e81f92ba608</stRef:instanceID>
<stRef:documentID>B4C00FF319085C77E5CD0403E55E459E</stRef:documentID>
</xmpMM:DerivedFrom>
<xmp:CreatorTool>Adobe Photoshop CS5 Windows</xmp:CreatorTool>
<photoshop:AuthorsPosition>Contributor</photoshop:AuthorsPosition>
<dc:description>
<rdf:Alt>
<rdf:li xml:lang="x-repair">This is a test.</rdf:li>
</rdf:Alt>
</dc:description>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
As you can see, libxmp seems to have added xml:lang="x-repair" to the tag containing the description text. For some odd reason, some programs seem to read this with a literal lang="x-repair" prepended to the description text. I've tried both GIMP and the Ubuntu built-in file properties menu, with the same erroneous results. However, various online metadata viewers predictably do not have this problem.
My Question:
Is it possible to add a description to an image using the python libxmp module WITHOUT automatically adding the xml:lang="x-repair" part? I think this would effectively work around the text rendering bug I've found in various programs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
