Skip to content

Use reducing_gap when resizing RGBA and LA images - #10208

Merged
radarhere merged 4 commits into
python-pillow:mainfrom
antonsoo:fix/alpha-resize-reducing-gap
Oct 15, 2026
Merged

radarhere merged 4 commits into
python-pillow:mainfrom
antonsoo:fix/alpha-resize-reducing-gap

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

RGBA and LA resizes drop reducing_gap when calling resize() on the premultiplied image. This also disables integer reduction in transparent PNG thumbnails, whose default gap is 2.0.

Changes proposed in this pull request:

  • Forward the existing option through the premultiplied-alpha resize.
  • Add resize and default-thumbnail regressions, including a manually calculated alpha block average.
  • Add a release note for the affected modes.
from PIL import Image

im = Image.new("RGBA", (16, 16), (255, 0, 0, 0))
for x in range(0, 16, 4):
    im.paste((255, 255, 255, 255), (x, 0, x + 1, 16))
out = im.resize((4, 4), Image.Resampling.LANCZOS, reducing_gap=1.0)
print(list(out.get_flattened_data())[:4])

Before, the alpha values are [76, 60, 69, 44]. With the requested integer reduction they are all 64: each 4x4 block contains four opaque white pixels and twelve transparent pixels. Visible RGB remains white.

A local export audit of six existing 512x512 transparent game icons and two bundled PNGs corrects 312 gap-aware results, including 24 independently calculated block means. The 144 default/nearest/ordinary controls and 96 already-correct results retain exact hashes. At gap 2, summed nine-sample medians for the six native-size RGBA icon resizes to 32x32 improve from 18.91ms to 4.95ms; thumbnails from 19.81ms to 5.84ms. These are local asset-export measurements, not a production incident or general performance guarantee.

All four regressions fail before and pass after. Source selftest, affected suites, the full Python 3.12 suite (5,240 passed, 471 skipped, three existing xfails), configured mypy, lint/format/docs/packaging hooks and manual Pyroma pass. The baseline has 5,236 passes with the same skips/xfails. No native kernel or dependency changes.

@radarhere radarhere added the 🤖-assisted AI-assisted label Oct 14, 2026
Comment thread docs/releasenotes/13.0.0.rst Outdated
@radarhere
radarhere force-pushed the fix/alpha-resize-reducing-gap branch from beb940a to be67ee0 Compare October 15, 2026 03:18
@radarhere
radarhere force-pushed the fix/alpha-resize-reducing-gap branch from be67ee0 to f7340f4 Compare October 15, 2026 03:24
@radarhere
radarhere enabled auto-merge (squash) October 15, 2026 03:28
@radarhere radarhere changed the title Honor reducing_gap when resizing RGBA and LA images Use reducing_gap when resizing RGBA and LA images Oct 15, 2026
@radarhere
radarhere disabled auto-merge October 15, 2026 03:28
@radarhere
radarhere enabled auto-merge (squash) October 15, 2026 03:28
@radarhere
radarhere merged commit bc7e6f5 into python-pillow:main Oct 15, 2026
24 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants