Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PIL Image mode "P" -> "RGBA"

This is my issue:

import Image
im = Image.open("1.png")
im.show()
print im.mode
im.convert("RGBA").save("2.png")

Well, with my image you can see the difference.
My question is: how do I convert it properly?

Image: original

Result: result

NOTE: The original image has a semi-transparent glow, the result has a solid green "glow"

like image 649
mDroidd Avatar asked Sep 17 '12 15:09

mDroidd


2 Answers

This issue was reported here:

https://bitbucket.org/effbot/pil-2009-raclette/issue/8/corrupting-images-in-palette-mode

In March 2012, a comment says it's now fixed in development version of PIL. The most recent released version is 1.1.7, so the fix won't be available until 1.2 comes out. PIL updates very slowly, so don't expect this to come out soon.

like image 163
jterrace Avatar answered Sep 28 '22 03:09

jterrace


Unfortunately your PNG image is a type that PIL doesn't handle very well - a paletted image with an alpha channel. When you open the image, the alpha is thrown away and there's no way to get it back.

This is different from the usual palette transparency where one index of the palette is used to denote fully transparent pixels.

like image 23
Mark Ransom Avatar answered Sep 28 '22 04:09

Mark Ransom