Merge pull request #4625 from radarhere/thumbnail

This commit is contained in:
Hugo van Kemenade 2020-05-25 17:08:25 +03:00 committed by GitHub
commit f4fb9c5403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -63,6 +63,12 @@ def test_aspect():
assert im.size == (75, 23) # ratio is 3.260869565217
def test_division_by_zero():
im = Image.new("L", (200, 2))
im.thumbnail((75, 75))
assert im.size == (75, 1)
def test_float():
im = Image.new("L", (128, 128))
im.thumbnail((99.9, 99.9))

View File

@ -2277,7 +2277,9 @@ class Image:
if x / y >= aspect:
x = round_aspect(y * aspect, key=lambda n: abs(aspect - n / y))
else:
y = round_aspect(x / aspect, key=lambda n: abs(aspect - x / n))
y = round_aspect(
x / aspect, key=lambda n: 0 if n == 0 else abs(aspect - x / n)
)
size = (x, y)
box = None