mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Make key an argument
This commit is contained in:
parent
8f21d0ddf0
commit
84c33abaa0
|
@ -2240,19 +2240,15 @@ class Image:
|
||||||
if x >= self.width and y >= self.height:
|
if x >= self.width and y >= self.height:
|
||||||
return
|
return
|
||||||
|
|
||||||
def round_aspect(number):
|
def round_aspect(number, key):
|
||||||
if x / y >= aspect:
|
|
||||||
key = lambda n: abs(aspect - n / y) # noqa: E731
|
|
||||||
else:
|
|
||||||
key = lambda n: abs(aspect - x / n) # noqa: E731
|
|
||||||
return max(min(math.floor(number), math.ceil(number), key=key), 1)
|
return max(min(math.floor(number), math.ceil(number), key=key), 1)
|
||||||
|
|
||||||
# preserve aspect ratio
|
# preserve aspect ratio
|
||||||
aspect = self.width / self.height
|
aspect = self.width / self.height
|
||||||
if x / y >= aspect:
|
if x / y >= aspect:
|
||||||
x = round_aspect(y * aspect)
|
x = round_aspect(y * aspect, key=lambda n: abs(aspect - n / y))
|
||||||
else:
|
else:
|
||||||
y = round_aspect(x / aspect)
|
y = round_aspect(x / aspect, key=lambda n: abs(aspect - x / n))
|
||||||
size = (x, y)
|
size = (x, y)
|
||||||
|
|
||||||
box = None
|
box = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user