"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to access EXIF ​​data in Python?

How to access EXIF ​​data in Python?

Posted on 2025-04-13
Browse:152

How Do I Access EXIF Data in Python?

How to Access EXIF Data in Python

EXIF (Exchangeable Image File Format) data provides valuable metadata about an image, including details about the camera, settings, and even GPS coordinates. In Python, accessing EXIF data from an image is straightforward using the _getexif() method of the PIL Image class.

PIL Method:

import PIL.Image

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

This method returns a dictionary indexed by EXIF numeric tags. If you prefer tag names as dictionary keys, you can use the following code:

import PIL.ExifTags

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

The resulting dictionary now contains EXIF data indexed by tag names, providing a more intuitive way to access specific metadata.

Release Statement This article is reproduced on: 1729584978 If there is any infringement, please contact [email protected] to delete it.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3