Skip to content

Commit

Permalink
Make key an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
orlnub123 committed Feb 22, 2020
1 parent 8f21d0d commit 84c33ab
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/PIL/Image.py
Expand Up @@ -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
Expand Down

0 comments on commit 84c33ab

Please sign in to comment.