Is it possible to add IPTC data to a JPG using python when no such data already exists?
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.
精彩评论