From fcc570b772d8cb66508becb911ba0f1ec0f5a7b4 Mon Sep 17 00:00:00 2001 From: Daniel Rheinbay Date: Sat, 5 Sep 2015 21:46:16 +0200 Subject: [PATCH] Enlargen images to fit the target resolution, keeping their aspect ratio, if they are too small. --- airframe/airframe.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/airframe/airframe.py b/airframe/airframe.py index 8775476..af8bbe2 100755 --- a/airframe/airframe.py +++ b/airframe/airframe.py @@ -156,6 +156,15 @@ def resize_pictures(self, photo_filenames): if im.size[0] > size[0] or im.size[1] > size[1]: im.thumbnail(size, Image.ANTIALIAS) im.save(infile) + elif im.size[0] < size[0] and im.size[1] < size[1]: + width_factor = float(size[0])/im.size[0] + height_factor = float(size[1])/im.size[1] + target_factor = min(height_factor, width_factor) + target_width = int(im.size[0]*target_factor) + target_height = int(im.size[1]*target_factor) + result = im.resize((target_width, target_height), Image.BICUBIC) + result.save(infile) + result.close() im.close()