1

I have been searching for hours for the ability to edit / add tags or basically keywords of/to an image via Python. I wanted to change metadata of images so I had to use Piexif library and found it completely great but there is a problem which XPKeywords requires type 'bytes' instead of 'Ascii' for some reason.

I've tried using IPTCInfo library to just edit the keywords but unfortunately didn't go out that good like I wanted to. I've also tried converting the string to bytes via 'b' prefix but still the same problem remains.

4

2 回答 2

1

我已经通过使用 Piexif 自己弄清楚了。对于任何有同样问题的人;解决方案是元标记是'XPKeywords',我必须使用带有参数'utf16'的'encode'函数将关键字字符串编码为UCS2(如此处所述https://exiv2.org/tags.html )。评论也是如此(元标记:XPComment)。我希望我有所帮助!

于 2019-03-30T19:22:41.357 回答
0

尝试PyExifTool。它是 Phil Harvey 的exiftool的包装器,可让您对图像的元数据进行大量控制。

于 2019-03-28T19:24:03.633 回答