Fix Python – In Python, how do I read the exif data for an image?

Question

Asked By – TIMEX

I’m using PIL. How do I turn the EXIF data of a picture into a dictionary?

Now we will see solution for issue: In Python, how do I read the exif data for an image?


Answer

You can use the _getexif() protected method of a PIL Image.

import PIL.Image
img = PIL.Image.open('img.jpg')
exif_data = img._getexif()

This should give you a dictionary indexed by EXIF numeric tags. If you want the dictionary indexed by the actual EXIF tag name strings, try something like:

import PIL.ExifTags
exif = {
    PIL.ExifTags.TAGS[k]: v
    for k, v in img._getexif().items()
    if k in PIL.ExifTags.TAGS
}

This question is answered By – payne

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0