As part of an app using Pillow, I want to update exif for a bunch of photos, including artist names, titles, etc. So far, I've been using piexif to do so. However I ran into an encoding problem:
import PIL.Image
import piexif
img = PIL.Image.open("photo.jpg")
exif_dict = piexif.load(img.info["exif"])
exif_dict.get("0th").update({
315: "Lebœuf", # ExifTag for "Artist"
})
img.save("photo.jpg", "jpeg", exif=exif_dict)
UnicodeEncodeError: 'latin-1' codec can't encode character '\u0153' in position 3: ordinal not in range(256)
Encoding and its errors are a nightmare, one life will not suffice for me to grasp only the spirit of it. I understand that the character œ
is not part of the latin1 encoding, which piexif uses without control over it. However, if I add the exif tag manually on, say, Windows 10 explorer, I can successfully add that character and even retrieve it through piexif.load()
. My understanding is such as it seems not necessary to impose the latin1 encoding? Is there a workaround or another module I could use?