Draw Hebrew text on image using image module (python)

I am trying to use the Image module to create Hebrew caption bitmaps. when printing from the shell (in standby mode), I was able to print Hebrew, but when I try to draw text into a bitmap, it draws some inscriptions ascii.

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 would be greatly appreciated.

+3
source share
2 answers

Give it a try a = u"ืืจื™ืืœ".

Otherwise, try PyCairo . It has advanced typographic processing, which may work better.

+1
source

, , unicode, ,

a = u"ืืจื™ืืœ" #like this
a = unicode("ืืจื™ืืœ", "UTF-8") #or like this

. ? :.

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

, :

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

, ascii ( - faaaaar ascii) .

+1

Source: https://habr.com/ru/post/1730751/


All Articles