1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 10:26:17 +00:00

update pic rotation when generate thumbnail

This commit is contained in:
lian
2017-04-14 14:43:11 +08:00
parent b0754e31bb
commit b594025f2b

View File

@@ -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