Skip to content

Instantly share code, notes, and snippets.

@jpstroop
Created October 23, 2016 16:19
Show Gist options
  • Save jpstroop/58a21d02370c8ba34dc8f0fdd4206d70 to your computer and use it in GitHub Desktop.
Save jpstroop/58a21d02370c8ba34dc8f0fdd4206d70 to your computer and use it in GitHub Desktop.
Get EXIF, IPTC Metadata, etc. with Python & PIllow
from PIL import Image
from PIL.ExifTags import GPSTAGS
from PIL.ExifTags import TAGS
# Keys are listed here:
# https://github.com/python-pillow/Pillow/blob/master/PIL/ExifTags.py
def _map_key(k):
try:
return TAGS[k]
except KeyError:
return GPSTAGS.get(k, k)
def get_exif(image_path):
metadata = {}
with Image.open(image_path) as i:
info = i._getexif()
try:
[ metadata.__setitem__(_map_key(k), v) for k, v in info.items() ]
return metadata
except AttributeError:
return None
@fajela
Copy link

fajela commented Jul 14, 2020

the urls for the keys returns 404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment