我试图从“.nef”文件中提取exif信息,以便根据检索到的数据自动将文件排序到文件夹中。
根据我的阅读,PIL似乎是将信息输入Python的一个很好的选择。
我已经安装了PIL,它正确地导入,就像PIL.Image模块一样。
当我试图调用'PIL.Image._getexif()‘时,问题就出现了
from PIL import Image
from PIL.ExifTags import TAGS
firstfile = 'link to file'
exif = Image._getexif(firstfile)
这将得到以下错误:
AttributeError: 'module' object has no attribute '_getexif'
代码的较长版本也会出现错误:
def get_exif(fn):
ret = {}
i = Image.open(fn)
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
Image.close(fn)
return ret
exifinfo = get_exif(firstfile)
但以下几个方面都失败了:
AttributeError: _getexif
也许我安装错了?为什么不能调用'_getexif()‘?
注意:谷歌唯一直接搜索"AttributeError:‘模块’对象没有属性'_getexif'“的结果是旧的/404‘d’d没有帮助,让我相信这不是一个常见的问题。
发布于 2016-10-28 09:02:11
看起来,PIL并不是我想要完成的一个合适的模块。
通过使用PyExifTool从nef文件中提取EXIF信息,我能够达到目的(根据EXIF信息对文件夹中的项进行排序)。
发布于 2022-03-16 12:27:56
下面是一个工作片段,如果你坚持PIL,但它似乎有更好的模块,产生更多的结果。
https://pypi.org/project/exif/
from PIL import Image
from PIL.ExifTags import TAGS
ret = {}
with Image.open(img_path) as file:
info = file.getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret
https://stackoverflow.com/questions/40215380
复制相似问题