#python #python-imaging-library #jpeg #exif
#python #python-imaging-library #jpeg #exif
Вопрос:
XPComment и XPKeywords не отображаются при записи метаданных exif.
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?
Ответ №1:
Он должен быть закодирован в формате 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