Question

I'm trying to print the EXIF of an image. This is my code:

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

But it it gives an error:

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>

How to solve this error?

Was it helpful?

Solution

you should use the _getexif() method of that comes bundled in PIL's Image module:

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

or also image.info['exif']:

>>> image.info['exif'][0:20]
'Exif\x00\x00II*\x00\x08\x00\x00\x00\t\x00\x0f\x01\x02\x00'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top