Merge pull request #3632 from radarhere/thumbnail

Do not resize in Image.thumbnail if already the destination size
This commit is contained in:
Hugo 2019-02-27 23:37:20 +02:00 committed by GitHub
commit d9f5f44799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -1,4 +1,5 @@
from .helper import PillowTestCase, hopper
from PIL import Image
class TestImageThumbnail(PillowTestCase):
@ -35,3 +36,14 @@ class TestImageThumbnail(PillowTestCase):
im = hopper().resize((128, 128))
im.thumbnail((100, 100))
self.assert_image(im, im.mode, (100, 100))
def test_no_resize(self):
# Check that draft() can resize the image to the destination size
im = Image.open("Tests/images/hopper.jpg")
im.draft(None, (64, 64))
self.assertEqual(im.size, (64, 64))
# Test thumbnail(), where only draft() is necessary to resize the image
im = Image.open("Tests/images/hopper.jpg")
im.thumbnail((64, 64))
self.assert_image(im, im.mode, (64, 64))

View File

@ -2128,11 +2128,12 @@ class Image(object):
self.draft(None, size)
im = self.resize(size, resample)
if self.size != size:
im = self.resize(size, resample)
self.im = im.im
self.mode = im.mode
self._size = size
self.im = im.im
self._size = size
self.mode = self.im.mode
self.readonly = 0
self.pyaccess = None