Fixed ZeroDivisionError in thumbnail

This commit is contained in:
Andrew Murray 2020-05-15 18:29:52 +10:00
parent 4634eafe3c
commit b8ec793898
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