From d9a98a7e27ee5e0bdad37e4c052a85ec4ef7d3d1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 4 Feb 2020 19:34:39 -0800 Subject: [PATCH] Use voussoirkit.imagetools for fit_into_bounds function. --- resize.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/resize.py b/resize.py index edfdea5..6efff3b 100644 --- a/resize.py +++ b/resize.py @@ -2,25 +2,9 @@ import os from PIL import Image import sys +from voussoirkit import imagetools from voussoirkit import winglob -def fit_into_bounds(image_width, image_height, frame_width, frame_height): - ''' - Given the w+h of the image and the w+h of the frame, - return new w+h that fits the image into the frame - while maintaining the aspect ratio. - - (1920, 1080, 400, 400) -> (400, 225) - ''' - width_ratio = frame_width / image_width - height_ratio = frame_height / image_height - ratio = min(width_ratio, height_ratio) - - new_width = int(image_width * ratio) - new_height = int(image_height * ratio) - - return (new_width, new_height) - filenames = sys.argv[1] filenames = winglob.glob(filenames) @@ -41,9 +25,9 @@ for filename in filenames: (image_width, image_height) = i.size if new_x == 0: - (new_x, new_y) = fit_into_bounds(image_width, image_height, 10000000, new_y) + (new_x, new_y) = imagetools.fit_into_bounds(image_width, image_height, 10000000, new_y) if new_y == 0: - (new_x, new_y) = fit_into_bounds(image_width, image_height, new_x, 10000000) + (new_x, new_y) = imagetools.fit_into_bounds(image_width, image_height, new_x, 10000000) print(i.size, new_x, new_y) i = i.resize( (new_x, new_y), Image.ANTIALIAS)