You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python读取图片自定义描述标签(Windows标签/Adobe Bridge关键词)

读取图片自定义标签的实现方案

你提到的Windows系统「描述→标签」、Adobe Bridge中keywords这类自定义标签,不属于标准EXIF字段范畴,一般存储在IPTC元数据或XMP元数据的dc:subject字段中,所以常规仅读取EXIF的代码无法获取,以下是两种可直接使用的Python实现方案:

方案1:使用pyexiv2库(推荐,兼容性最高)

pyexiv2支持JPG、PNG、RAW等常见图片格式,可同时读写EXIF、IPTC、XMP三类元数据,无需额外依赖系统工具。

  • 安装命令:
    pip install pyexiv2
  • 读取示例代码:
from pyexiv2 import Image

# 替换为你的图片路径
img = Image(r"C:\Users\xxx\Pictures\test.jpg")

# 优先读取IPTC字段的关键词
iptc_data = img.read_iptc()
iptc_keywords = iptc_data.get("Iptc.Application2.Keywords", [])
print("IPTC存储的自定义标签:", iptc_keywords)

# IPTC无结果时读取XMP字段的关键词
xmp_data = img.read_xmp()
xmp_keywords = xmp_data.get("Xmp.dc.subject", [])
print("XMP存储的自定义标签:", xmp_keywords)

方案2:使用iptcinfo3库(轻量,仅处理IPTC元数据)

如果仅需要读取IPTC格式存储的关键词,不需要处理其他元数据,可以使用更轻量的iptcinfo3库。

  • 安装命令:
    pip install iptcinfo3
  • 读取示例代码:
from iptcinfo3 import IPTCInfo

# 替换为你的图片路径,force=True表示忽略小的元数据格式错误
info = IPTCInfo(r"C:\Users\xxx\Pictures\test.jpg", force=True)
keywords = info["keywords"]
print("读取到的自定义标签:", keywords)

注意:如果是PNG、WebP等非JPG格式的图片,优先使用pyexiv2方案,兼容性更好。

内容的提问来源于stack exchange,提问作者rioZg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 20:45:01