Drawing Hebrew text to and image using Image module (python)

被刻印的时光 ゝ 提交于 2019-12-31 02:49:06

问题


This is an issue I already asked about and several got answers but the problem remained. when I try to write in hebrew to an image using Image module I get instead of the hebrew lettring some other (ascii??) lettering. if I convert to unicode or ascii I get an error that it doesn't support. I got here a reference to a code that does what I want in chinese:

import sys

import Imag

import ImageDraw

import ImageFont

import _imaging

txt = '你好,世界!'

font = ImageFont.truetype('c:/test/simsun.ttc',24)

im = Image.new("RGBA",(300,200),(0,0,0))

draw = ImageDraw.Draw(im)

#draw.text( (0,50), u'你好,世界!', font=font)

draw.text( (0,50), unicode(txt,'UTF-8'), font=font)

but then I get an error:ImportError:

The _imagingft C module is not installed.

the same goes when I try to use standrad hebrew font 'arial.ttf' (with hebrew string ofcourse). as you can see I have imported _imaging succsefuly so the problem doesn't lay there as suggested by effbot.org.

it seem that the problem is with the Imagefont.truetype(...).

any help will be very appriciated


回答1:


Sounds like PIL was built without FreeType support. Install the FreeType dev files and rebuild PIL again.




回答2:


the problem was the PIL 1.1.7 doesn't work well with windows XP. the same code runs well under linux or with XP but with PIL 1.1.6 mystory is solved



来源:https://stackoverflow.com/questions/2182787/drawing-hebrew-text-to-and-image-using-image-module-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!