PIl, text and Windows 2000
Max Møller Rasmussen
maxm at normik.dk
Mon May 21 05:38:31 EDT 2001
> From: Ben [mailto:b.e.n. at .r.e.h.a.m.e...c.o.m]
> I am currently having a particularly hard time getting some text down
> onto a 2 bit png file using PIL and i was wondering
> if anyone has been successful in doing this could you please provide
> me with some pointers or sample code.
Here is a script that automatically creates buttons from a default image and
some text.
Maybe there is something there to pilfer.
regards Max M
---------------------------------
buttonList = {}
buttonList['02_home.gif'] = 'Ölwechselung'
buttonList['02_01_somewhere.gif'] = 'Klares Bekenntnis zur Umwelt'
buttonList['02_02_dude.gif'] = 'Hey Dude'
import ImageDraw, ImageFont
import Image
# Set font
arial =
ImageFont.load('C:/root/pythonScripts/PILTest/phontz/Verdana_12_100.pil')
im = Image.open("C:/root/pythonScripts/PILTest/redButton.gif")
width, height = im.size
middle = width/2
for fileName, theText in buttonList.items():
aCopy = im.copy()
# render the text
draw = ImageDraw.Draw(aCopy)
draw.setfont(arial)
draw.setink(255)
textWidth, textHeight = draw.textsize(theText)
textMiddle = textWidth/2
fontPlacement = middle - textMiddle
print textWidth
draw.text((fontPlacement, -3), theText)
aCopy.save('C:/root/pythonScripts/PILTest/' + fileName)
More information about the Python-list
mailing list