Using the Python Imaging Library (PIL) I get a:
"ValueError: image has wrong mode"
when trying to convert an RGBA mode image to a P mode image. I couldn't find any evidence for the fact that it is possible. The material I found on the convert() method doesn't state that it isn't possible. I am wondering if I am doing something wrong or if this is just not possible.
Here is my code:
from PIL import Image
transImage = Image.open("transparent_8_bit.png")
print transImage.mode
transImageRGBA = transImage.convert("RGBA")
print transImageRGBA.mode
transImageP = transImageRGBA.convert('P', palette=Image.ADAPTIVE)
print transImageP.mode
Here is the image "transparent_8_bit.png": http://s24.postimg.org/4xqzu9n4h/transparent_8_bit.png
The output should be:
P
RGBA
P
However, I get this:
P
RGBA
Traceback (most recent call last):
File "mode_test.py", line 7, in <module>
transImageP = transImageRGBA.convert('P', palette=Image.ADAPTIVE)
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 689, in convert
im = self.im.quantize(colors)
ValueError: image has wrong mode
Is PIL just not able to do this?
Thanks for your help!