当不存在此类数据时,是否可以使用 python 将 IPTC 数据添加到 JPG 中?

发布于 2024-08-31 02:56:39 字数 278 浏览 5 评论 0原文

使用Python下的IPTCInfo模块(http://snippets.dzone.com/posts/show/768 了解更多信息)可以读取、修改 IPTC 信息并将其写入图片。

但是,如果 JPG 尚无 IPTC 信息,则模块只会引发异常。它本身似乎无法创建和添加此元数据信息。

还有哪些替代方案?我用谷歌搜索了过去一个小时,但毫无结果。

With the IPTCInfo module 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浊酒尽余欢 2024-09-07 02:56:39

尝试 pyexiv2。它是 exiv2 的包装,exiv2 是根据 GPL 许可的 C++ 图片元数据(EXIF、IPTC、XMP)库。它运作得很好。

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

沒落の蓅哖 2024-09-07 02:56:39

创建 IPTCInfo 对象时使用 force=True 选项。然后,即使原始文件中缺少 IPTC 数据,也会将其写入。

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

从源文件中的文档:

如果force==True,则强制始终返回对象。这
允许您开始向没有 IPTC 信息的文件添加内容
然后保存。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文