10-05-2021, 09:03 PM
(10-05-2021, 08:25 PM)Ofnuts Wrote:Code:
➤>import xml.etree.ElementTree as ET
➤># metadata as string
➤>metadata = pdb.gimp_image_get_metadata(image)
➤># Parse to XML Tree
➤>xmlTree=ET.fromstring(metadata)
➤># Find relevant item (the autho is the "Artist", the "Copyright" is actually
➤># the license name (for instance "CC-BY-SA")
➤># Brute force version
➤>authorItem=[item for item in xmlTree if 'Artist' in item.attrib['name']][0]
➤># Xpath version for the illuminati
➤>authorItem=xmlTree.findall("*[@name='Exif.Image.Artist']")
➤># Show what we got
➤> print authorItem.attrib['name'],'=',authorItem.text
Exif.Image.Artist = Ofnuts
➤># Update value
➤>authorItem.text='Someone Else'
➤># XML tree back to string
➤>metadataNew=ET.tostring(xmlTree)
➤># String back to image metadata
➤>pdb.gimp_image_set_metadata(image,metadataNew)
File ➤ Export as /tmp/ShowAuthor.jpg
Then in a terminal:
QEDCode:
➤ exiftool /tmp/ShowAuthor.jpg | grep Artist
Artist : Someone Else
Great work! Will this work as a plug-in with BIMP? Also is the XML version of the Copyright tag just "Exif.Image.License"? If not where can I check those properties?