By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,522 Members | 1,739 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,522 IT Pros & Developers. It's quick & easy.

non-ascii charater image gereration with PIL

P: n/a
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.

--
zooy
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> 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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.