2019-02-03 18:34:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2019-02-04 22:15:50 +03:00
|
|
|
from PIL import Image
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageThumbnail(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper()
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((100, 100))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assert_image(im, im.mode, (100, 100))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_aspect(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper()
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((100, 100))
|
|
|
|
self.assert_image(im, im.mode, (100, 100))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper().resize((128, 256))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((100, 100))
|
|
|
|
self.assert_image(im, im.mode, (50, 100))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper().resize((128, 256))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((50, 100))
|
|
|
|
self.assert_image(im, im.mode, (50, 100))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper().resize((256, 128))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((100, 100))
|
|
|
|
self.assert_image(im, im.mode, (100, 50))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper().resize((256, 128))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((100, 50))
|
|
|
|
self.assert_image(im, im.mode, (100, 50))
|
|
|
|
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper().resize((128, 128))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.thumbnail((100, 100))
|
|
|
|
self.assert_image(im, im.mode, (100, 100))
|
2019-02-04 22:15:50 +03:00
|
|
|
|
|
|
|
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))
|