I'm trying to write EXIF data to a jpg file using Pillow and Python 3. I don't understand why the following code is failing. Any help would be greatly appreciated.
fileName
is a valid full path and file name to a jpg file. I'm accessing the name from a QListWidget that displays photo file names and their images as icons. The overall idea is to iterate through the list of files in the QListWidget and update each file's EXIF data.
while S < self.lstPhotos.count():
fileName = str(self.lblPath.text() + "/" + self.lstPhotos.item(S).text())
im = Image.open(fileName)
exifdata = im._getexif()
exifdata[0x010f] = "Canon"
exifdata[0x0110] = "EOS 630"
im.save(fileName, exif=exifdata)
S += 1
The error I receive is:
Traceback (most recent call last):
File "/home/richard/Dropbox/Documents/Personal/Python/PhotOrg/src/photoOrgMain.py", line 372, in WriteEXIFData
im.save(fileName, exif=exifdata)
File "/home/richard/.local/lib/python2.7/site-packages/PIL/Image.py", line 1698, in save
save_handler(self, fp, filename)
File "/home/richard/.local/lib/python2.7/site-packages/PIL/JpegImagePlugin.py", line 725, in _save
ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
File "/home/richard/.local/lib/python2.7/site-packages/PIL/ImageFile.py", line 490, in _save
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
File "/home/richard/.local/lib/python2.7/site-packages/PIL/Image.py", line 439, in _getencoder
return encoder(mode, *args + extra)
TypeError: argument 13 must be string or read-only buffer, not dict
I'm guessing that Pillow does not want the EXIF data in dictionary form, but that's the format Pillow itself retrieves from the file.
I can't find documentation online about what format the EXIF data should be in. I assumed it should be in the same format that Pillow generated with _getexif()
call.
I am using Python 3. I'm using the latest version of Pillow. Pillow installed itself at .local/lib/python2.7/site-packages/PIL/ and its other functions seem to be working under Python 3.