diff --git a/Tests/test_image_resize.py b/Tests/test_image_resize.py index a49abe1b9..50c5a99bd 100644 --- a/Tests/test_image_resize.py +++ b/Tests/test_image_resize.py @@ -250,3 +250,7 @@ class TestImageResize: for mode in "1", "P": im = hopper(mode) assert im.resize((20, 20), Image.NEAREST) == im.resize((20, 20)) + + for mode in "I;16", "I;16L", "I;16B", "BGR;15", "BGR;16": + im = hopper(mode) + assert im.resize((20, 20), Image.NEAREST) == im.resize((20, 20)) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index ebeaf3c74..6529db2be 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1849,7 +1849,7 @@ class Image: min(self.size[1], math.ceil(box[3] + support_y)), ) - def resize(self, size, resample=BICUBIC, box=None, reducing_gap=None): + def resize(self, size, resample=None, box=None, reducing_gap=None): """ Returns a resized copy of this image. @@ -1859,9 +1859,11 @@ class Image: one of :py:data:`PIL.Image.NEAREST`, :py:data:`PIL.Image.BOX`, :py:data:`PIL.Image.BILINEAR`, :py:data:`PIL.Image.HAMMING`, :py:data:`PIL.Image.BICUBIC` or :py:data:`PIL.Image.LANCZOS`. - Default filter is :py:data:`PIL.Image.BICUBIC`. - If the image has mode "1" or "P", it is - always set to :py:data:`PIL.Image.NEAREST`. + If the image has mode "1" or "P", it is always set to + :py:data:`PIL.Image.NEAREST`. + If the image mode specifies a number of bits, such as "I;16", then the + default filter is :py:data:`PIL.Image.NEAREST`. + Otherwise, the default filter is :py:data:`PIL.Image.BICUBIC`. See: :ref:`concept-filters`. :param box: An optional 4-tuple of floats providing the source image region to be scaled. @@ -1882,7 +1884,10 @@ class Image: :returns: An :py:class:`~PIL.Image.Image` object. """ - if resample not in (NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING): + if resample is None: + type_special = ";" in self.mode + resample = NEAREST if type_special else BICUBIC + elif resample not in (NEAREST, BILINEAR, BICUBIC, LANCZOS, BOX, HAMMING): message = f"Unknown resampling filter ({resample})." filters = [