From b594025f2bb542a808690a941a57482ec067c8e2 Mon Sep 17 00:00:00 2001 From: lian Date: Fri, 14 Apr 2017 14:43:11 +0800 Subject: [PATCH] update pic rotation when generate thumbnail --- seahub/thumbnail/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/seahub/thumbnail/utils.py b/seahub/thumbnail/utils.py index bbd380c741..23ca830a5e 100644 --- a/seahub/thumbnail/utils.py +++ b/seahub/thumbnail/utils.py @@ -33,27 +33,31 @@ def get_rotated_image(image): orientation = exif.get(0x0112) if isinstance(exif, dict) else 1 # rotate image according to Orientation info + + # im.transpose(method) + # Returns a flipped or rotated copy of an image. + # Method can be one of the following: FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, or ROTATE_270. if orientation == 2: # Vertical image image = image.transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 3: # Rotation 180 - image = image.transpose(Image.ROTATE_180) + image = image.rotate(180) elif orientation == 4: + image = image.rotate(180).transpose(Image.FLIP_LEFT_RIGHT) # Horizontal image - image = image.transpose(Image.FLIP_TOP_BOTTOM) elif orientation == 5: # Horizontal image + Rotation 90 CCW - image = image.transpose(Image.FLIP_TOP_BOTTOM).transpose(Image.ROTATE_90) + image = image.rotate(-90).transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 6: # Rotation 270 - image = image.transpose(Image.ROTATE_270) + image = image.rotate(-90) elif orientation == 7: # Horizontal image + Rotation 270 - image = image.transpose(Image.FLIP_TOP_BOTTOM).transpose(Image.ROTATE_270) + image = image.rotate(90).transpose(Image.FLIP_LEFT_RIGHT) elif orientation == 8: # Rotation 90 - image = image.transpose(Image.ROTATE_90) + image = image.rotate(90) return image