pythonimagepython-imaging-libraryexif

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


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


Solution

  • 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
    }