Created
November 23, 2018 08:40
-
-
Save codeif/4a31fe911c072cc983de71cbad71189e to your computer and use it in GitHub Desktop.
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
def get_right_img(image): | |
# https://stackoverflow.com/a/6218425/7403042 | |
if not hasattr(image, '_getexif'): | |
return image | |
image_exif = image._getexif() | |
if not image_exif: | |
return image | |
image_orientation = image_exif[274] | |
# Rotate depending on orientation. | |
if image_orientation == 3: | |
image = image.rotate(180, expand=True) | |
elif image_orientation == 6: | |
image = image.rotate(-90, expand=True) | |
elif image_orientation == 8: | |
image = image.rotate(90, expand=True) | |
return image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment