[Image-SIG] Cookbook for making transparent indexed png images ?
Rodrigo Dias Arruda Senra
rodsenra at gpr.com.br
Wed Oct 27 20:04:34 CEST 2004
Hi,
I'm trying to generate a Transparent PNG image, supported
by both Mozilla and IE6.0. The code below gets the job done for
Mozilla, but fails for IE.
When I generate indexed PNG images, I get a black background instead
of a transparent one.
Moreover, I saw references in the mailing list to the
.info['transparency'], but I do not know how to used it
or even if this is still supported ?
I would appreciate any hint or documentation pointers on the subject.
best regards,
Senra
<code>
def make_label(label, fontsize, fg=(0,0,0), bg=(0,0,0)):
font = ImageFont.truetype("FUNKY.TTF", fontsize)
fontMask = Image.new("RGBA", (10,10), None)
draw = ImageDraw.Draw(fontMask)
sizex,sizey = draw.textsize(label, font=font)
fontMask = fontMask.resize((sizex, sizey))
draw = ImageDraw.Draw(fontMask)
bimsize = (sizex, sizey)
width, height = bimsize
xoff = yoff = 0
draw.text((xoff,yoff), label,fill=fg,font=font)
# My ultimate goal was to generate transparent indexed images
#fontMask = fontMask.convert('P', dither=Image.NONE, # palette=Image.ANTIALIAS)
# saw references to that in the mailing list
#
#fontMask.info['transparency']=(0,0,0)
fontMask.save('x.png','PNG')
</code>
More information about the Image-SIG
mailing list