[Image-SIG] More PNG battles
Ray Pasco
pascor at hotpop.com
Sat Nov 6 05:11:42 CET 2004
OK, now I'm getting strung out. I'm creating and saving a RGBA PNG,
but when it's converted to a P mode not only is the image damaged, but
the encoder
*insists* on adding a value of 10 to the given palette index used to set
transparency:
Does anyone know what is going on ?
(XP using 1.1.5b1 so I can use the get/setpalette methods)
--------------------------------------------
import Image
# (mode, size, color=r,g,b,a), no transparency
imgRgba = Image.new ('RGBA', (100, 100), (0, 85, 185, 255)) #
dark blue
imgRgba.paste ( (185, 85, 0, 255), ( 10, 10, 90, 90) ) #
dark red
# paste an "alpha-tized" color in the center of the image
# (r, g, b, a), (L, Top, R, Bot)
imgRgba.paste ( ( 0, 0, 0, 0), ( 20, 20, 80, 80) ) #
black center
imgRgba.save ('TRANSPARENT.RGBA.png')
# Now convert to a palettized format and save to a new file
imgPlt = imgRgba.convert ('P')
# I happen to know that the palette index for the transparency color is
index 0.
# ??? Why must 10 be subtracted from the transparency color index value
# for the encoder to get it right ???
imgPlt.save ('TRANS.PLT.png', transparency=0-10)
More information about the Image-SIG
mailing list