non-ascii charater image gereration with PIL

Damjan gdamjan at gmail.com
Mon Apr 11 18:57:05 EDT 2005


> PIL has 'text(position, string, options)' method in its ImageDraw module.
> Does this work with unicode or other 2byte encoded string?
> It seems not working on my python2.3.5 with PIL 1.1.5.

Yes, just tried and it works (python-2.4/PIL 1.1.5), but you also need a
font that supports your characters, see this script:

text = unicode('some cyrillic text: здраво', 'utf-8')
from PIL import ImageFont, ImageDraw, Image
image = Image.new('RGB',(400,300))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(".fonts/dejavu-ttf/DejaVuSans.ttf", 12)
draw.text((10, 10), text, font=font)
image.save('wow.jpg')

-- 
damjan



More information about the Python-list mailing list