开发者

Is it possible to add IPTC data to a JPG using python when no such data already exists?

开发者 https://www.devze.com 2022-12-29 20:26 出处:网络
With the IPTCInfo module开发者_StackOverflow under Python (http://snippets.dzone.com/posts/show/768 for more info) it\'s possible to read, modify and write IPTC info to pictures.

With the IPTCInfo module开发者_StackOverflow under Python (http://snippets.dzone.com/posts/show/768 for more info) it's possible to read, modify and write IPTC info to pictures.

However, if a JPG doesn't already have IPTC information, the module simply raises an exception. It doesn't seem to be able to create and add this metadata information itself.

What alternatives are there? I've googled for the past hour but to no avail whatsoever.


Try pyexiv2. It's a wrapper of exiv2, the C++ picture metadata (EXIF, IPTC, XMP) library licensed under GPL. It works pretty well.


Use force=True option when creating IPTCInfo object. Then IPTC data will be written even if it is missing in the original file.

info = IPTCInfo(input_file, force=True, inp_charset='utf8')

From the docs in the source file:

If force==True, than forces an object to always be returned. This allows you to start adding stuff to files that don't have IPTC info and then save it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号