Created
July 1, 2013 10:56
-
-
Save lepture/5899948 to your computer and use it in GitHub Desktop.
Rotate it right for browser displaying images.
This file contains 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
# coding: utf-8 | |
def fix_orientation(img): | |
orientation = img.metadata.get('exif:Orientation', 1) | |
if orientation == 1: | |
# do nothing | |
return img | |
elif orientation == 2: | |
# vertical mirror | |
img.flop() | |
elif orientation == 3: | |
img.rotate(180) | |
elif orientation == 4: | |
# horizontal mirror | |
img.flip() | |
elif orientation == 5: | |
img.flip() | |
img.rotate(270) | |
elif orientation == 6: | |
img.rotate(270) | |
elif orientation == 7: | |
img.flop() | |
img.rotate(270) | |
elif orientation == 8: | |
img.rotate(90) | |
return img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment