Python Pillow EXIF 数据未返回

标签 python python-2.7 exif python-imaging-library

我正在使用一些示例代码尝试从示例 .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/

相关文章:

python - Ansible 中的 if 语句与 Jinja2 变量

powershell - 将 EXIF DateTaken 设置为文件创建时间

php - exif_imagetype 在 Windows 中不起作用

python - 使用键作为标题和值作为列将字典写入 csv 时出现问题

Python 响应数据类型 - 如何访问数据

python - 用备用值替换 Python 字符串中的 "tokens"

python-2.7 - ctypes 的模拟导入失败,阅读文档时操作数不受支持

python - 打开 : differences between python 2 and 3

python - 使用 Python 将 "Date Taken"Exif/XMP 信息添加到 TIF 文件

python - 将python文件导入到我的pycharm中,位于同一目录中