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