Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remap_palette loses transparency information #6349

Closed
JensRestemeier opened this issue Jun 5, 2022 · 1 comment · Fixed by #6350
Closed

remap_palette loses transparency information #6349

JensRestemeier opened this issue Jun 5, 2022 · 1 comment · Fixed by #6350
Labels

Comments

@JensRestemeier
Copy link

What did you do?

I have palettized images that use "0xFF 0x00 0xFF" to mark transparency. After converting this into an alpha channel I want to reorder colours so that transparency is at the start of the palette.
I am using "image.remap_palette" to reorder colours.

What did you expect to happen?

I expect the transparency information in a palette to be preserved when reordering colours.

What actually happened?

Transparency information in a palette is lost when reordering colours

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.9.5 (64 bit)
  • Pillow: 9.1.1
from PIL import Image

img = Image.new("P", (256, 256))
pixel = []
for y in range(256):
    for x in range(256):
        v = ((y // 16) & 1) ^ ((x // 16) & 1)
        pixel.append(v)
img.putdata(pixel)

pal = [255,0,0,0 ,0,255,0,255] + [255] * 248 * 4
img.putpalette(pal, "RGBA")
img.save("test_A.png")

img = img.remap_palette([1,0])
img.save("test_B.png")

This produces two images: test_A is the input, test_B is the output
Both images should look identical when opened in a program like GIMP. The colours (red and green) are correctly swapped, though test_B loses the transparency on red.

@radarhere
Copy link
Member

I've created PR #6350 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants