Reputation: 1456
XPComment and XPKeywords does not appear when writing exif metadata.
from PIL import Image
filepath = "yourFilepath.jpg"
image = Image.open(filepath)
XPComment = 0x9C9C
XPKeywords = 0x9C9E
exifdata = image.getexif()
exifdata[XPComment] = "new comment"
exifdata[XPKeywords] = "new keyword;"
image.save(filepath, exif=exifdata)
# ???? where's my exif data yo?
Upvotes: 3
Views: 1046
Reputation: 1456
It needs to be encoded in utf-16 format. The necessary encoding may vary depending on your computer.
from PIL import Image
filepath = "yourFilepath.jpg"
image = Image.open(filepath)
XPComment = 0x9C9C
XPKeywords = 0x9C9E
exifdata = image.getexif()
exifdata[XPComment] = "new comment".encode("utf16")
exifdata[XPKeywords] = "new keyword;".encode("utf16")
image.save(filepath, exif=exifdata)
# it appears! :D
Upvotes: 2