From c5ee036380aa835860f3e308d56a56e754815d0e Mon Sep 17 00:00:00 2001 From: webfiltered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:42:43 +1000 Subject: [PATCH] Fix ConstrainImage increases size Current When ConstrainImage is provided with an image that is smaller than max width & height, it will always scale the image up. New behaviour If an image already falls within the constraint min/max bounds, it is not scaled. --- py/constrain_image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/constrain_image.py b/py/constrain_image.py index c3631b3..1c76889 100644 --- a/py/constrain_image.py +++ b/py/constrain_image.py @@ -35,8 +35,8 @@ def constrain_image(self, images, max_width, max_height, min_width, min_height, current_width, current_height = img.size aspect_ratio = current_width / current_height - constrained_width = max(min(current_width, min_width), max_width) - constrained_height = max(min(current_height, min_height), max_height) + constrained_width = min(max(current_width, min_width), max_width) + constrained_height = min(max(current_height, min_height), max_height) if constrained_width / constrained_height > aspect_ratio: constrained_width = max(int(constrained_height * aspect_ratio), min_width)