[Image-SIG] centering graphical text with PIL?

Alec Bennett wrybread at gmail.com
Tue Dec 12 00:06:28 CET 2006


I'm trying to center some graphical text using the PIL. Anyone have a clue
how to do this?

If there's some way of knowing how big the resulting graphical word is, I
could obviously center it.

For example:

import ImageFont, ImageDraw, Image

image_file = "button.jpg"
image = Image.open(image_file)
font = "arial.ttf"

draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font, 12)
draw.text((1, 1), "hi there", font=font)

image.save("temp.jpg")


In the above code, the 1, 1 is the x & y coordinates for the text.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20061211/68c48fcc/attachment.htm 


More information about the Image-SIG mailing list