Changed Image.thumbnail method's size calculation

now it's faster and more pythonic
This commit is contained in:
thodnev 2016-08-25 02:59:20 +03:00 committed by GitHub
parent 1165f0f7fc
commit 651432b723

View File

@ -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)