When working with images in Python, it's often useful to extract metadata stored in the Exchangeable Image File Format (EXIF). The Python Imaging Library (PIL) provides a convenient mechanism for accessing EXIF data as a dictionary.
To retrieve EXIF data, you can utilize the _getexif() method within PIL. Here's an example:
import PIL.Image
img = PIL.Image.open('img.jpg')
exif_data = img._getexif()
This will return a dictionary with numeric keys. Each key represents an EXIF tag ID, and the corresponding value is the associated data.
If you prefer indexed by the human-readable tag names instead, you can use the TAGS attribute of the PIL.ExifTags module:
import PIL.ExifTags
exif = {
PIL.ExifTags.TAGS[k]: v
for k, v in img._getexif().items()
if k in PIL.ExifTags.TAGS
}
This dictionary will now contain the EXIF data indexed by tag names.
With these methods, you can easily access and interpret EXIF metadata in Python, aiding in image analysis, manipulation, and organization tasks.
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