mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
Merge pull request #3859 from radarhere/error
Updated resampling filter error messages
This commit is contained in:
commit
11059cb684
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user