Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Batch Metadata updating with BIMP.
#1
Hello. I am very new to scripting and plug-ins in general. I am trying to create a script that works with BIMP (Batch processing of GIMP) that gets the metadata from each image and updates selected fields while keeping the non-updated ones. I mainly want to update the Copyright of each of the images that are batch processed. I know I can use exiftool for this, but I am also using BIMP for more than just editing metadata and would like to only use BIMP for all these purposes. I know I need to use pdb.gimp_image_get_metadata(image) and pdb.gimp_image_set_metadata(image,data). But I just don't know how to code the script to do what I want it to do.

Thank you in advance!
Reply
#2
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:
Code:
➤ exiftool /tmp/ShowAuthor.jpg | grep Artist
Artist                          : Someone Else
QED
Reply
#3
(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:
Code:
➤ exiftool /tmp/ShowAuthor.jpg | grep Artist
Artist                          : Someone Else
QED

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?
Reply
#4
(10-05-2021, 09:03 PM)YeboiXd Wrote:
(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:
Code:
➤ exiftool /tmp/ShowAuthor.jpg | grep Artist
Artist                          : Someone Else
QED

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?

No, this is the core of a plugin, needs some boilerplate around it.
Reply
#5
(10-06-2021, 08:10 PM)Ofnuts Wrote:
(10-05-2021, 09:03 PM)YeboiXd Wrote:
(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:
Code:
➤ exiftool /tmp/ShowAuthor.jpg | grep Artist
Artist                          : Someone Else
QED

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?

No, this is the core of a plugin, needs some boilerplate around it.
Got it! I will go ahead and try it.
Reply


Forum Jump: