[Image-SIG] Question about PIL and transparency

Weldner Alves darkstar at brturbo.com.br
Fri May 6 19:33:45 CEST 2005

What I wanna do is simple:
I just want to write a string on a transparent background. Here is my code:

import Image, ImageDraw, ImageFont

im = Image.new("P",(500,500), 'white')
fonte = ImageFont.truetype("comicbd.ttf",15)
draw = ImageDraw.Draw(im)

im.info['transparency'] = 255 
"""(the background is white, then white is my transparency)"""
draw.text((0,0), "HERE GOES THE STRING", fill='black', font=fonte)

im.save("something.png", "PNG")

Now when I go to the prompt:

>>> im = Image.open('something.png')
>>> im.info.items()
>>> im.info["transparency"]=255
>>> im.save("anything.png", "PNG")
>>> im = Image.open('anything.png')
>>> im.info.items()

There was suposed to be a "transparency" with value 255 inside the info dict.
So whats wrong ?

More information about the Image-SIG mailing list