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

2024-07-04 05:05:43 发布

您现在位置:Python中文网/ 问答频道 /正文

写入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?

Tags: 数据fromimageimportnewpilopenexif
1条回答
网友
1楼 · 发布于 2024-07-04 05:05:43

它需要以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

相关问题 更多 >

    热门问题