mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-16 18:24:45 +03:00
Changed Image.thumbnail method's size calculation
now it's faster and more pythonic
This commit is contained in:
parent
1165f0f7fc
commit
651432b723
16
PIL/Image.py
16
PIL/Image.py
|
@ -1785,18 +1785,14 @@ class Image(object):
|
|||
:returns: None
|
||||
"""
|
||||
|
||||
# preserve aspect ratio
|
||||
x, y = self.size
|
||||
if x > size[0]:
|
||||
y = int(max(y * size[0] / x, 1))
|
||||
x = int(size[0])
|
||||
if y > size[1]:
|
||||
x = int(max(x * size[1] / y, 1))
|
||||
y = int(size[1])
|
||||
size = x, y
|
||||
|
||||
if size == self.size:
|
||||
return
|
||||
# preserve aspect ratio
|
||||
x, y = self.size
|
||||
if x > size[0] or y > size[1]:
|
||||
factor = max(x/size[0], y/size[1])
|
||||
x, y = int(x/factor), int(y/factor)
|
||||
size = x, y
|
||||
|
||||
self.draft(None, size)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user