gpt4 book ai didi

Python Pillow EXIF 数据未返回

转载 作者:行者123 更新时间:2023-12-01 04:21:47 25 4
gpt4 key购买 nike

我正在使用一些示例代码尝试从示例 .jpg 图像返回 exif 信息。 Python代码是:

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif(fn):
ret = {}
i = Image.open('C:\Users\Me\Desktop\Sample1.jpg')
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret

代码运行没有错误,但不输出任何内容。另外,尝试将其输出到文件中,但也无法写出任何信息。有人能发现为什么这没有返回任何东西吗?谢谢你!

最佳答案

我不知道你想做什么,但这段代码对我有用(从 python 2.7 和 3 开始):

from PIL import Image
from PIL.ExifTags import TAGS

def get_exif():
i = Image.open('/path/to/imagefile.jpg')
info = i._getexif()
return {TAGS.get(tag): value for tag, value in info.items()}

print get_exif()

关于Python Pillow EXIF 数据未返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33597311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com