Skip to content

Conversation

radarhere
Copy link
Member

Resolves #9151 with two changes.

  1. Currently,
p = hopper("P")
a = Image.new("L", p.size)
pa = Image.merge("PA", (p, a))
print(pa.palette.colors)

returns populated palette data, but

print(pa.getpalette())

is empty. This fixes that.

  1. When converting RGBA to PA, rather than using the C method topalette(), quality can be improved by using the Python quantize() to convert the RGB channels to P, and copying the A channel exactly by using split() and merge().

Copy link

@bryghtlabs-richard bryghtlabs-richard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@radarhere radarhere merged commit 2275993 into python-pillow:main Oct 4, 2025
54 checks passed
@radarhere radarhere deleted the rgba_pa branch October 4, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overly large PA palette
3 participants