Open kinexm opened 8 years ago
I am having the same issue. Is there a way around this?
This is an issue I've encountered with images uploaded from iOS devices as well. I believe it's due to embedded EXIF data in the image, presumably from the iOS camera app, see http://sylvana.net/jpegcrop/exif_orientation.html for more details.
You'll need to either:
if hasattr(image, '_getexif'):
exif_info = image._getexif()
if exif_info:
# default orientation to 1 if no orientation data
orientation = exif_info.get(274, 1)
# orientation types:
# http://sylvana.net/jpegcrop/exif_orientation.html
if orientation == 1: # proper orientation, do nothing
pass
elif orientation == 2: # horizontally flipped
image = image.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3: # rotated 180 degrees
image = image.transpose(Image.ROTATE_180)
elif orientation == 4: # vertically flipped
image = image.transpose(Image.FLIP_TOP_BOTTOM)
elif orientation == 5:
# rotated 90 degrees then horizontally flipped (transpose)
image = image.transpose(Image.FLIP_LEFT_RIGHT).transpose(
Image.ROTATE_90)
elif orientation == 6: # rotated 270 degrees
image = image.transpose(Image.ROTATE_270)
elif orientation == 7:
# rotated 270 degrees then flipped horizontally (transverse)
image = image.transpose(Image.FLIP_LEFT_RIGHT).transpose(
Image.ROTATE_270)
elif orientation == 8: # rotated 90 degrees
image = image.transpose(Image.ROTATE_90)
In some cases, when a image is taken using the camera and uploaded, the result image (Cropped) gets rotates. Here are the steps:
By default, the rotation shouldn't happen and the picture should in the right rotation. Let me know if you need more information or screenshots.