Skip to content

Instantly share code, notes, and snippets.

@rafaelcaricio
Created November 14, 2013 12:12
Show Gist options
  • Save rafaelcaricio/7465821 to your computer and use it in GitHub Desktop.
Save rafaelcaricio/7465821 to your computer and use it in GitHub Desktop.
Simple script to show exif info stored in a image file.
#!/usr/bin/env python
import argparse
try:
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
except ImportError:
print "You need to install PIL. Please check: http://www.pythonware.com/products/pil/"
def decode_gps_info(exif):
gpsinfo = {}
if 'GPSInfo' in exif:
for key in exif['GPSInfo'].keys():
decode = GPSTAGS.get(key,key)
gpsinfo[decode] = exif['GPSInfo'][key]
exif['GPSInfo'] = gpsinfo
def get_exif_metadata(image_path):
ret = {}
image = Image.open(image_path)
if hasattr(image, '_getexif'):
exifinfo = image._getexif()
if exifinfo is not None:
for tag, value in exifinfo.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
decode_gps_info(ret)
return ret
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Display exif metadata of a image if available.')
parser.add_argument('image_path', metavar='image_path', help='Complete image path.')
args = parser.parse_args()
if args.image_path:
for key, value in get_exif_metadata(args.image_path).items():
print key, value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment