1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 18:29:23 +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 orientation = exif.get(0x0112) if isinstance(exif, dict) else 1
# rotate image according to Orientation info # 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: if orientation == 2:
# Vertical image # Vertical image
image = image.transpose(Image.FLIP_LEFT_RIGHT) image = image.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3: elif orientation == 3:
# Rotation 180 # Rotation 180
image = image.transpose(Image.ROTATE_180) image = image.rotate(180)
elif orientation == 4: elif orientation == 4:
image = image.rotate(180).transpose(Image.FLIP_LEFT_RIGHT)
# Horizontal image # Horizontal image
image = image.transpose(Image.FLIP_TOP_BOTTOM)
elif orientation == 5: elif orientation == 5:
# Horizontal image + Rotation 90 CCW # 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: elif orientation == 6:
# Rotation 270 # Rotation 270
image = image.transpose(Image.ROTATE_270) image = image.rotate(-90)
elif orientation == 7: elif orientation == 7:
# Horizontal image + Rotation 270 # 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: elif orientation == 8:
# Rotation 90 # Rotation 90
image = image.transpose(Image.ROTATE_90) image = image.rotate(90)
return image return image