diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index ae1cf6e3d..384657d98 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -160,6 +160,15 @@ class TestImageTransform(PillowTestCase): im = hopper() self.assertRaises(ValueError, im.transform, (100, 100), None) + def test_unknown_resampling_filter(self): + im = hopper() + (w, h) = im.size + for resample in (Image.BOX, "unknown"): + self.assertRaises(ValueError, im.transform, (100, 100), Image.EXTENT, + (0, 0, + w, h), + resample) + class TestImageTransformAffine(PillowTestCase): transform = Image.AFFINE diff --git a/src/PIL/Image.py b/src/PIL/Image.py index b9e569a83..4e84fa53d 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1794,7 +1794,18 @@ class Image(object): if resample not in ( NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING, ): - raise ValueError("unknown resampling filter") + message = "Unknown resampling filter ({}).".format(resample) + + filters = ["{} ({})".format(filter[1], filter[0]) for filter in ( + (NEAREST, "Image.NEAREST"), + (LANCZOS, "Image.LANCZOS"), + (BILINEAR, "Image.BILINEAR"), + (BICUBIC, "Image.BICUBIC"), + (BOX, "Image.BOX"), + (HAMMING, "Image.HAMMING") + )] + raise ValueError( + message+" Use "+", ".join(filters[:-1])+" or "+filters[-1]) size = tuple(size) @@ -2263,7 +2274,22 @@ class Image(object): raise ValueError("unknown transformation method") if resample not in (NEAREST, BILINEAR, BICUBIC): - raise ValueError("unknown resampling filter") + if resample in (BOX, HAMMING, LANCZOS): + message = { + BOX: "Image.BOX", + HAMMING: "Image.HAMMING", + LANCZOS: "Image.LANCZOS/Image.ANTIALIAS" + }[resample]+" ({}) cannot be used.".format(resample) + else: + message = "Unknown resampling filter ({}).".format(resample) + + filters = ["{} ({})".format(filter[1], filter[0]) for filter in ( + (NEAREST, "Image.NEAREST"), + (BILINEAR, "Image.BILINEAR"), + (BICUBIC, "Image.BICUBIC") + )] + raise ValueError( + message+" Use "+", ".join(filters[:-1])+" or "+filters[-1]) image.load()