Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Tests/test_image_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
8 changes: 8 additions & 0 deletions docs/releasenotes/13.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading