开发者

draw hebrew text to an image using Image module (python)

I am trying to use Image module in order to ma开发者_如何学JAVAke bitmaps with hebrew lettering in it. when printing from the shell (idle) I managed to print hebrew, but when trying to draw text to a bitmap it draws some ascii lettering.

this is the code:

import Image

import ImageDraw

a = "אריאל" #or any other hebrew string

im=Image.new('RGB',(200,200),(100,100,100)) #type file,size,Background color

d=ImageDraw.Draw(im)

d.text((0,0),a) #should draw the string

im.show()

any help will be very appreciated.


Try a = u"אריאל".

Failing that, try PyCairo. It has advanced typography handling that may work better.


This site mentions that to draw Chinese text, they had to specify that the string was unicode, so you should do the same, e.g.

a = u"אריאל" #like this
a = unicode("אריאל", "UTF-8") #or like this

They also specified a font. Is there an appropriate one for Hebrew? e.g.:

font = ImageFont.truetype('simsun.ttc',24)

and then specify that font when drawing text, e.g.:

d.text( (0,0), a, font=font)

I think your code is drawing an ascii string (and Hebrew is faaaaar away from ascii) in the wrong font.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜