Drawing multilingual text using PIL

I'm having trouble drawing multilingual text using PIL. Say I want to draw a text - "ひ ら が γͺ - Hiragana, νžˆλΌκ°€λ‚˜". But the PIL function ImageDraw.text () only accepts one font at a time, so I cannot draw this text correctly because it requires the sharing of English, Japanese, and Korean fonts.

So far, I have not been able to find a simple solution, for example, transferring several fonts to PIL so that it can select the appropriate font for each Unicode character (for example, modern SDKs or web browsers).

I think I should iterate over each character and determine which font to use for each character. But I can't help but think that there should be an easier way to do this.

Am I going in the right direction? Is there an easier way?

PS) It is good to use a different language or a different image library if there is a much better solution.

+8
fonts unicode imaging python-imaging-library cjk
source share
1 answer

You just need to choose a Unicode font. Example:

import Image import ImageFont, ImageDraw image=Image.new("RGB",[320,320]) draw = ImageDraw.Draw(image) a=u"γ²γ‚‰γŒγͺ - Hiragana, νžˆλΌκ°€λ‚˜" font=ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf",14) draw.text((50, 50), a, font=font) image.save("a.png") 

Outputs this

+9
source share

All Articles