From 7df96e86eb6f6ff058cf88d3cd721758ec2ec7e2 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 17 Jan 2022 13:47:47 -0800 Subject: [PATCH] Make ratio comparison more explicit --- mangle/image.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mangle/image.py b/mangle/image.py index 0b5ea36..5fd7e38 100644 --- a/mangle/image.py +++ b/mangle/image.py @@ -137,9 +137,12 @@ def quantizeImage(image, palette): def scaleCropImage(image, size): widthDev, heightDev = size widthImg, heightImg = image.size + + imgRatio = float(widthImg) / float(heightImg) + devRatio = float(widthDev) / float(heightDev) # don't crop 2 page spreads. - if (float(widthImg) / float(heightImg)) > (float(widthDev) / float(heightDev)): + if imgRatio > devRatio: return resizeImage(image, size) return ImageOps.fit(image, size, Image.ANTIALIAS)