diff --git a/Tests/test_image_thumbnail.py b/Tests/test_image_thumbnail.py index bd7c98c28..c6db3b59b 100644 --- a/Tests/test_image_thumbnail.py +++ b/Tests/test_image_thumbnail.py @@ -1,6 +1,6 @@ from PIL import Image -from .helper import PillowTestCase, hopper +from .helper import PillowTestCase, hopper, fromstring, tostring class TestImageThumbnail(PillowTestCase): @@ -47,3 +47,14 @@ class TestImageThumbnail(PillowTestCase): im = Image.open("Tests/images/hopper.jpg") im.thumbnail((64, 64)) self.assert_image(im, im.mode, (64, 64)) + + def test_DCT_scaling_edges(self): + # Make an image with red borders with size (N * 8) + 1 to cross DCT grid + im = Image.new('RGB', (97, 97), 'red') + im.paste(Image.new('RGB', (95, 95)), (1, 1)) + + thumb = fromstring(tostring(im, "JPEG", quality=95)) + thumb.thumbnail((24, 24), Image.BICUBIC) + + ref = im.resize((24, 24), Image.BICUBIC) + self.assert_image_similar(thumb, ref, 2) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 05ff9239e..d2b44ff09 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2212,14 +2212,17 @@ class Image(object): x = int(max(x * size[1] / y, 1)) y = int(size[1]) size = x, y + box = None if size == self.size: return - self.draft(None, size) + res = self.draft(None, size) + if res is not None: + box = res[1] if self.size != size: - im = self.resize(size, resample) + im = self.resize(size, resample, box=box) self.im = im.im self._size = size