2013-06-26 54 views
1

我正在尝试打印图像的EXIF。 这是我的代码:正在读取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> 

如何解决这个问题?

+0

这似乎是一个错误,并固定在主:https://开头github.com/dahlia/wand/commit/11235ee204a48e060498e63a9171c55c1ba808d4 – minhee

+0

所以这是一个错误...谢谢。 – user2524343

+0

对不起,我应该如何使用固定版本?我用新的替换了旧的image.py和tests/image_test.py,并使用python setup.py install进行安装。但现在我得到这个错误:ImportError:无法导入名称encode_filename – user2524343

回答

0

你应该使用的是_getexif()方法捆绑在PIL的图片模块:

>>> 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' 
+0

另外,我从来没有见过'image.metadata'被其他任何地方使用过(但我可能是错的,我希望)试图在一堆图像上,他们似乎都错过了,无论我尝试什么 –

+0

我使用的是Python 3,所以没有PIL。 而且我已经根据此页面编写了该代码: https://wand.readthedocs.org/en/0.3-maintenance/whatsnew/0.3.html Exif部分。 – user2524343

+0

你仍然可以使用枕头,友好的PIL叉:https://pypi.python.org/pypi/Pillow/ –