I am using XMP tags to perform backup of the original name of my pictures before renaming them. I'm using this command to perform backup (works in Windows):
exiftool -P -overwrite_original_in_place "-XMP:PreservedFileName<Filename" "-XMP:Title<${filename;s/\.[^.]*$//}" filename
At the end, I have the following tags set for my picture file:
> exiftool -X -H P1050122.jpg
...
<XMP-dc:Title et:id='title'>P1050122</XMP-dc:Title>
<XMP-xmpMM:PreservedFileName et:id='PreservedFileName'>P1050122.jpg</XMP-xmpMM:PreservedFileName>
...
I would like to read and write those properties using Pillow, but I'm not finding a way. The following code doesn't seem to be able to show the tags above:
from PIL import Image, ExifTags
i = Image.open('P1050122.jpg')
exif_data = i.getexif().get_ifd(ExifTags.IFD.Exif)
print(exif_data)
{36864: b'0220', 37121: b'\x01\x02\x03\x00', 37122: 4.0, 36867: '2011:06:19 20:11:56', 36868: '2011:06:19 20:11:56', 37377: 6.322, 37378: 3.0, 37380: 0.0, 37381: 3.0, 37383: 5, 37384: 1, 37385: 16, 37386: 14.8, 40961: 1, 40962: 2304, 41990: 0, 40963: 1728, 41992: 0, 41993: 0, 41994: 0, 41996: 3, 41495: 2, 41728: b'\x03', 282: 72.0, 283: 72.0, 33434: 0.0125, 33437: 2.8, 40965: 844, 41729: b'\x01', 34850: 2, 41730: b'\x00\x02\x00\x02\x01\x00\x02\x01', 41985: 0, 34855: 50, 41986: 0, 40960: b'0100', 41987: 0, 41988: 0.0, 41989: 89, 41991: 0}
Any ideas on how I can get them?
XMP data are distinct from EXIF data, so you need to do it like this:
from PIL import Image
i = Image.open('iPhoneSample.JPG')
print(i.getxmp())
{'xmpmeta': {'xmptk': 'Image::ExifTool 12.76',
'RDF': {'Description': [{'about': '',
'title': {'Alt': {'li': {'lang': 'x-default', 'text': 'iPhoneSample'}}}},
{'about': '', 'PreservedFileName': 'iPhoneSample.JPG'}]}}}
Note that you may need to install/upgrade the defusedxml
package beforehand with command akin to:
python3 -m pip install --upgrade defusedxml