From 77210e410d5dc5fe16b20d5e783867d3efc6cb75 Mon Sep 17 00:00:00 2001 From: homm Date: Fri, 2 Dec 2016 16:33:48 +0300 Subject: [PATCH] =?UTF-8?q?test=20for=20common=20modes=20and=20filters=20p?= =?UTF-8?q?ass=20box=20for=20RGBA=20=E2=86=92=20RGBa=20conversion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PIL/Image.py | 4 ++-- Tests/test_image_resample.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index a3171aeaa..84122655a 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1558,10 +1558,10 @@ class Image(object): resample = NEAREST if self.mode == 'LA': - return self.convert('La').resize(size, resample).convert('LA') + return self.convert('La').resize(size, resample, box).convert('LA') if self.mode == 'RGBA': - return self.convert('RGBa').resize(size, resample).convert('RGBA') + return self.convert('RGBa').resize(size, resample, box).convert('RGBA') self.load() diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index bbdbf2a02..17461c868 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -451,6 +451,15 @@ class CoreResampleBoxTest(PillowTestCase): with self.assertRaisesRegexp(AssertionError, "difference 29\."): self.assert_image_similar(reference, without_box, 5) + def test_formats(self): + for resample in [Image.NEAREST, Image.BILINEAR]: + for mode in ['RGB', 'L', 'RGBA', 'LA', 'I', '']: + im = hopper(mode) + box = (20, 20, im.size[0] - 20, im.size[1] - 20) + with_box = im.resize((32, 32), resample, box) + cropped = im.crop(box).resize((32, 32), resample) + self.assert_image_similar(cropped, with_box, 0.4) + if __name__ == '__main__': unittest.main()