使用PIL.Image._getexif()访问exif信息时遇到问题 [英] Trouble accessing exif information with PIL.Image._getexif()

查看:2777
本文介绍了使用PIL.Image._getexif()访问exif信息时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从'.nef'文件中提取exif信息,以便根据检索到的数据自动将文件排序到文件夹中。

I am attempting to pull exif information from '.nef' files for the purposes of automatically sorting files into folders based on the retrieved data.

根据我的阅读,看起来PIL是将信息输入Python的不错选择。

Based on my reading, it appears that PIL is a good choice for getting the information into Python.

我安装了PIL并且导入正确,PIL.Image模块也是如此。

I have PIL installed and it imports correctly, as does the PIL.Image module.

当我尝试调用'PIL.Image._getexif()'时出现问题

The problem arises when I attempt to call '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'

代码的较长版本也会收到错误:

A longer version of the code also gets an error:

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

也许我有PIL装错了吗?为什么'_getexif()'无法被调用?

Perhaps I have PIL installed wrong? Why is '_getexif()' not able to be called?

注意:
直接搜索AttributeError:'module'对象的唯一google结果没有属性'_getexif'陈旧/ 404没有帮助,让我相信这不是一个常见的问题。

Notes: The only google results for a direct search of "AttributeError: 'module' object has no attribute '_getexif'" are old/404'd not helpful, leading me to believe this is not a common problem to have.

推荐答案

看来PIL不适合我想要完成的任务。

It would appear that PIL is not an appropriate module for what I was trying to accomplish.

我能够实现目标(在文件夹中排序项目)基于EXIF信息)使用 PyExifTool 从nef文件中提取EXIF信息。

I was able to achieve my ends (sorting items in a folder based on EXIF info) by using PyExifTool to extract EXIF info from nef files.

这篇关于使用PIL.Image._getexif()访问exif信息时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆