How Do I Access EXIF Data in Python?

Mary-Kate Olsen
Release: 2024-10-22 19:27:37
Original
706 people have browsed it

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:

<code class="python">import PIL.Image

img = PIL.Image.open('img.jpg')
exif_data = img._getexif()</code>
Copy after login

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

<code class="python">import PIL.ExifTags

exif = {
    PIL.ExifTags.TAGS[k]: v
    for k, v in img._getexif().items()
    if k in PIL.ExifTags.TAGS
}</code>
Copy after login

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

The above is the detailed content of How Do I Access EXIF Data in Python?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template