Created
October 23, 2016 16:19
-
-
Save jpstroop/58a21d02370c8ba34dc8f0fdd4206d70 to your computer and use it in GitHub Desktop.
Get EXIF, IPTC Metadata, etc. with Python & PIllow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the urls for the keys returns 404