写入 exif 元数据时不出现 XPComment 和 XPKeywords

XPComment and XPKeywords does not appear when writing exif metadata

写入 exif 元数据时,XPComment 和 XPKeywords 不会出现。

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?

需要编码为utf-16格式。必要的编码可能因您的计算机而异。

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