non-ascii charater image gereration with PIL

D

Daewon YOON

Hi. I'm a newbie to this python world.

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.

How can I accomplish this task? Specifically I'm trying to generate
Hangeul characters (Korean characters) images from txts encoded
either in euc-kr, cp949, or unicode with TTF files.
 
D

Damjan

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')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,234
Messages
2,571,178
Members
47,809
Latest member
Adisty

Latest Threads

Top