diff --git a/Tests/test_image_resize.py b/Tests/test_image_resize.py index f37fd4b04e7..9dc24f47b68 100644 --- a/Tests/test_image_resize.py +++ b/Tests/test_image_resize.py @@ -282,6 +282,18 @@ def test_reducing_gap_8( assert_image_equal(ref, im) + @pytest.mark.parametrize("mode", ("RGBA", "LA")) + def test_reducing_gap_alpha(self, mode: str) -> None: + with Image.open("Tests/images/transparent.png") as im: + im_converted = im.convert(mode) + + # Premultiply the alpha manually + premultiplied = im_converted.convert({"RGBA": "RGBa", "LA": "La"}[mode]) + expected = premultiplied.resize((16, 16), reducing_gap=2).convert(mode) + + # Test that resizing the image applies the alpha in the same way + assert_image_equal(im_converted.resize((16, 16), reducing_gap=2), expected) + @pytest.mark.parametrize( "box, epsilon", (((0, 0, 512, 512), 5.5), ((0.9, 1.7, 128, 128), 9.5)), diff --git a/docs/releasenotes/13.0.0.rst b/docs/releasenotes/13.0.0.rst index 0763dccf8fb..a9fcc0dc510 100644 --- a/docs/releasenotes/13.0.0.rst +++ b/docs/releasenotes/13.0.0.rst @@ -183,6 +183,14 @@ installed on the system with the expected name (e.g. ``libharfbuzz.so.0``). All wheels are now linked against the HarfBuzz that Pillow ships, which may slightly change how text is rendered in scripts that rely on the auto-hinter. +Resizing images with alpha +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``reducing_gap`` argument to :py:meth:`~PIL.Image.Image.resize` is now +applied to RGBA and LA images. Previously, these modes ignored the argument, +including when called by :py:meth:`~PIL.Image.Image.thumbnail`, which uses +``reducing_gap=2.0`` by default. + Preserved transparency when padding or expanding images in ImageOps ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/PIL/Image.py b/src/PIL/Image.py index a55cdccd710..6dec284d086 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2420,7 +2420,7 @@ def resize( if self.mode in ["LA", "RGBA"] and resample != Resampling.NEAREST: im = self.convert({"LA": "La", "RGBA": "RGBa"}[self.mode]) - im = im.resize(size, resample, box) + im = im.resize(size, resample, box, reducing_gap) return im.convert(self.mode) self.load()