【问题标题】:Reading EXIF gives an error读取 EXIF 会出错
【发布时间】:2013-06-26 13:51:38
【问题描述】:

我正在尝试打印图像的 EXIF。 这是我的代码:

with Image(filename="/home/hapoofesgeli/Desktop/b.jpg") as image:
    for k, v in image.metadata.items():
        if k.startswith('exif:'):
            print(k, v)

但它给出了一个错误:

Traceback (most recent call last):
  File "/home/hapoofesgeli/Programming/Test/Test.py", line 5, in <module>
    for k, v in image.metadata.items():
  File "/usr/lib/python3.3/collections/abc.py", line 480, in __iter__
    yield (key, self._mapping[key])
  File "/usr/lib/python3.3/site-packages/wand/image.py", line 2260, in __getitem__
    raise TypeError('k must be a string, not ' + repr(format))
TypeError: k must be a string, not <built-in function format>

如何解决这个错误?

【问题讨论】:

  • 这似乎是一个错误,并在 master 中修复:github.com/dahlia/wand/commit/…
  • 所以这是一个错误...谢谢。
  • 对不起,我应该如何使用固定版本?我用新的替换了旧的 image.py 和 tests/image_test.py 并使用 python setup.py install 安装了它。但现在我收到此错误: ImportError: cannot import name encode_filename
  • 试试 pip install git+git@github.com/dahlia/wand.git@0.3-maintenance#egg=Wand-0.3.2dev
  • pip 给出了一个错误(预期版本规范),但我下载了 wand-0.3-maintenance.zip 并使用 python install 安装它,python 代码终于可以工作了。谢谢

标签: python-3.x imagemagick wand


【解决方案1】:

您应该使用捆绑在 PIL 的 Image 模块中的 _getexif() 方法:

>>> image = Image.open(os.getcwd() + '/canon-ixus.jpg')
>>> image._getexif()
{36864: '0210', 37121: '\x01\x02\x03\x00', .... }

或者image.info['exif']:

>>> image.info['exif'][0:20]
'Exif\x00\x00II*\x00\x08\x00\x00\x00\t\x00\x0f\x01\x02\x00'

【讨论】:

  • 另外,我从未见过image.metadata 在其他任何地方使用过(但我希望我可能是错的) 在一堆图像上尝试过,他们似乎都错过了这一点,无论如何我尝试什么
  • 我使用的是 Python 3,所以没有 PIL。我已经根据此页面编写了该代码:wand.readthedocs.org/en/0.3-maintenance/whatsnew/0.3.html Exif 部分。
  • 你仍然可以使用 Pillow,友好的 PIL 分支:pypi.python.org/pypi/Pillow
  • 感谢您的帮助,我可以得到 image._getexif() 的结果,但是我应该如何使用该结果呢?
  • 您打算如何在原始帖子中使用它?你想完成什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-16
  • 2015-07-02
  • 2020-04-22
  • 1970-01-01
  • 1970-01-01
  • 2014-09-06
  • 1970-01-01
相关资源
最近更新 更多