Trouble accessing exif information with PIL.Image._getexif()

久未见 提交于 2019-12-31 04:52:09

问题


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

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

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

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)

That gets this error:

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)

This fails with:

AttributeError: _getexif

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

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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/40215380/trouble-accessing-exif-information-with-pil-image-getexif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!