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.
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