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

TIMEX picture TIMEX · Jan 22, 2011 · Viewed 168k times · Source

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

Answer

payne picture payne · Jan 22, 2011

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
}