From 2fd4fa665fd0523c516ecca0a1ccbf3829e8373e Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Wed, 18 Apr 2018 13:57:44 +1000 Subject: [PATCH] resizer: Implement rotation Need to work on dimensions. --- tornado_gallery/resizer.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tornado_gallery/resizer.py b/tornado_gallery/resizer.py index a654c21..4b02472 100644 --- a/tornado_gallery/resizer.py +++ b/tornado_gallery/resizer.py @@ -190,12 +190,18 @@ class ResizerPool(object): # We do not, press on! pass + # Open the image + img = Image.open(open(orig_node.abs_path,'rb')) + + # Rotate if asked: + if rotation != 0: + img = img.rotate(rotation, expand=1) + # Resize! - orig = Image.open(open(orig_node.abs_path,'rb')) - resized = orig.resize((width, height), Image.LANCZOS) + img = img.resize((width, height), Image.LANCZOS) # Write out the new file. - resized.save(open(cache_path,'wb'), img_format.pil_fmt) + img.save(open(cache_path,'wb'), img_format.pil_fmt) # Return to caller log.info('Returning resized result')