Skip to content

Instantly share code, notes, and snippets.

@nitheeshas
Created June 1, 2016 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitheeshas/5855b4358c18161c2e5e70dd45956f44 to your computer and use it in GitHub Desktop.
Save nitheeshas/5855b4358c18161c2e5e70dd45956f44 to your computer and use it in GitHub Desktop.
from PIL import Image, ExifTags
import sys
'''
1 2 3 4 5 6 7 8
888888 888888 88 88 8888888888 88 88 8888888888
88 88 88 88 88 88 88 88 88 88 88 88
8888 8888 8888 8888 88 8888888888 8888888888 88
88 88 88 88
88 88 888888 888888
'''
def getOrientation(tag):
switcher = {
3: 180,
6: 270,
8: 90
}
return switcher.get(tag, "Undefined")
if __name__ == "__main__":
try:
image=Image.open(sys.argv[1])
except:
print "Cannot load image"
exit()
for tag in ExifTags.TAGS.keys():
if ExifTags.TAGS[tag]=='Orientation':
break
exif=dict(image._getexif().items())
print getOrientation(exif[tag])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment