I would like to add Russian text to the image. I use PIL 1.1.7 and Python 2.7 on Windows machine. Since PIL compiled without libfreetype library, I use the following on development server:
font_text = ImageFont.load('helvR24.pil')
draw.text((0, 0), 'Текст на русском', font=font_text)
(helvR24.pil
is taken from http://effbot.org/media/downloads/pilfonts.zip)
On Production environment I do the following:
font_text = ImageFont.truetype('HelveticaRegular.ttf', 24, encoding="utf-8")
draw.text((0, 0), 'Текст на русском', font=font_text)
(tried to use unic
, cp-1251
instead of utf-8
)
In both cases it doesn't display Russian characters ('squares' or dummy characters are displayed instead). I think it doesn't work on Development environment since most probably helvR24.pil
doesn't contain Russian characters (don't know how to check it). But HelveticaRegular.ttf
surely has it. I also checked that my .py
file has геа-8 encoding. And it doesn't display Russian characters even with default font:
draw.text((0, 0), 'Текст на русском', font=ImageFont.load_default())
What else should I try / verify? I've looked thru https://stackoverflow.com/a/18729512/604388 - it doesn't help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…