How to extract metadata from an image using python?

extract, image, metadata, python

Solution

Use `Pillow`, it's a fork of PIL that is still in active development, and supports python3. Here I use a dict generator to map the exif data to a dict

from PIL import Image, ExifTags
img = Image.open("/path/to/file.jpg")
exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS }

Problem

How can I extract metadata from an image using Python?

Original source

Related problems