[Image-SIG] Korean/unicode strings in PIL

Joris Vankerschaver joris.vankerschaver at gmail.com
Sun Jan 17 13:54:05 CET 2010

Dear all,

I would like to use PIL to generate thumbnails with Korean characters.  
Unfortunately,  the code that I use doesn't produce the correct output.  
Here is a small snippet, based on some PIL example code.

code = u'\uAC00'
letter = code.encode('UTF-8')

i = Image.new("RGB", (25,25))
d = ImageDraw.Draw(i)
f = ImageFont.truetype("AppleMyungjo.ttf", 12, encoding = "unic")
d.text((0,0), letter, font = f)
i.save(open("ga.png", "wb"), "PNG")

Here, "AppleMyungjo.ttf" is a font that has some Korean characters in 
it.  The program doesn't produce any errors, but the output image just 
contains garbage pixels (different ones based on the font I pick, but 
never the correct ones).  I've tried playing with the different options, 
but to no avail.  To see what the output should look like, simply do 
"print u'\uAC00'.encode('UTF-8')".

Does anyone have some sample code to produce 
Korean/Japanese/Chinese/random unicode text in images?

I'm afraid this might be a trivial problem, but the obvious google 
searches didn't yield anything useful.

Thanks a lot,
Joris Vankerschaver.

More information about the Image-SIG mailing list