From 84c33abaa097b50176f33b74ef97ceda2f17b48b Mon Sep 17 00:00:00 2001 From: orlnub123 Date: Sat, 22 Feb 2020 12:30:10 +0000 Subject: [PATCH] Make key an argument --- src/PIL/Image.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index cc9b349370a..b1e8ad3ea06 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2240,19 +2240,15 @@ def thumbnail(self, size, resample=BICUBIC, reducing_gap=2.0): if x >= self.width and y >= self.height: return - def round_aspect(number): - if x / y >= aspect: - key = lambda n: abs(aspect - n / y) # noqa: E731 - else: - key = lambda n: abs(aspect - x / n) # noqa: E731 + def round_aspect(number, key): return max(min(math.floor(number), math.ceil(number), key=key), 1) # preserve aspect ratio aspect = self.width / self.height if x / y >= aspect: - x = round_aspect(y * aspect) + x = round_aspect(y * aspect, key=lambda n: abs(aspect - n / y)) else: - y = round_aspect(x / aspect) + y = round_aspect(x / aspect, key=lambda n: abs(aspect - x / n)) size = (x, y) box = None