-
Right now trying to save an image with an RGBA palette as PNG raises an exception from PIL import Image
import numpy as np
palette = np.random.random_integers(0, 255, size=(16,4)).astype(np.uint8)
indices = np.random.random_integers(0, 16, size=(20, 10)).astype(np.uint16)
img = Image.fromarray(indices, mode='PA')
img.putpalette(palette)
img.save("test.png")
But at least Wikipedia states this should be possible:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think this comes back to the same distinction as #9242 - PA images store a palette index and an independent alpha value for each pixel. Your highlighted quote says, emphasis mine,
What I think your highlighted quote is describing is P mode image with an RGBA palette, where the alpha values are for the palette entries, not for the pixel values. So if I had a palette with only two entries, (255, 0, 0, 127) and (0, 255, 0, 255), I must choose between translucent red and opaque green. With just those entries, I can't have opaque red. That type of image can be saved as a PNG image with Pillow. from PIL import Image
import numpy as np
palette = np.random.random_integers(0, 255, size=(16,4)).astype(np.uint8)
indices = np.random.random_integers(0, 16, size=(20, 10)).astype(np.uint16)
img = Image.fromarray(indices, mode='P')
img.putpalette(palette, 'RGBA')
img.save("test.png") If you're interested in evidence from the specification, |
Beta Was this translation helpful? Give feedback.
I think this comes back to the same distinction as #9242 - PA images store a palette index and an independent alpha value for each pixel.
Your highlighted quote says, emphasis mine,
What I think your highlighted quote is describing is P mode image with an RGBA palette, where the alpha values are for the palette entries, not for the pixel values. So if I had a palette with only two entries, (255, 0, 0, 127) and (0, 255, 0, 255), I must choose between translucent red and opaque green. With just those entries, I can't have opaque red.
That type of image can be saved as a PNG image with Pillow.