From c7bef264bc455d191e0540fa8ac67d989438f929 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 17 Dec 2019 06:05:36 +1100 Subject: [PATCH] Allow thumbnail to accept non-integer size arguments --- Tests/test_image_thumbnail.py | 5 +++++ src/PIL/Image.py | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/test_image_thumbnail.py b/Tests/test_image_thumbnail.py index 30fe25557..5806e2a08 100644 --- a/Tests/test_image_thumbnail.py +++ b/Tests/test_image_thumbnail.py @@ -43,6 +43,11 @@ class TestImageThumbnail(PillowTestCase): im.thumbnail((33, 33)) self.assertEqual(im.size, (21, 33)) # ratio is 0.6363636364 + def test_float(self): + im = Image.new("L", (128, 128)) + im.thumbnail((99.9, 99.9)) + self.assertEqual(im.size, (100, 100)) + def test_no_resize(self): # Check that draft() can resize the image to the destination size with Image.open("Tests/images/hopper.jpg") as im: diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 613b3a361..981c8c818 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2138,10 +2138,10 @@ class Image: x, y = self.size if x > size[0]: y = max(round(y * size[0] / x), 1) - x = size[0] + x = round(size[0]) if y > size[1]: x = max(round(x * size[1] / y), 1) - y = size[1] + y = round(size[1]) size = x, y if size == self.size: