在 Python 中,如何读取图像的 exif 数据? [英] In Python, how do I read the exif data for an image?
本文介绍了在 Python 中,如何读取图像的 exif 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PIL.如何将图片的EXIF数据转成字典?
I'm using PIL. How do I turn the EXIF data of a picture into a dictionary?
推荐答案
您可以使用 PIL Image 的 _getexif()
保护方法.
You can use the _getexif()
protected method of a PIL Image.
import PIL.Image
img = PIL.Image.open('img.jpg')
exif_data = img._getexif()
这应该会给你一个由 EXIF 数字标签索引的字典.如果您希望字典由实际的 EXIF 标签名称字符串索引,请尝试以下操作:
This should give you a dictionary indexed by EXIF numeric tags. If you want the dictionary indexed by the actual EXIF tag name strings, try something like:
import PIL.ExifTags
exif = {
PIL.ExifTags.TAGS[k]: v
for k, v in img._getexif().items()
if k in PIL.ExifTags.TAGS
}
这篇关于在 Python 中,如何读取图像的 exif 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文