使用图像模块(python)将希伯来语文本绘制为图像
这是我已经问过的一个问题,并且有几个得到了答案,但问题仍然存在。 当我尝试使用图像模块用希伯来语写入图像时,我得到的不是希伯来语字母而是其他(ascii??)字母。如果我转换为 unicode 或 ascii,我会收到一个它不支持的错误。我在这里得到了一个代码的引用,该代码可以用中文完成我想要的操作:
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)
但随后我收到错误:ImportError:
未安装 _imagingft C 模块。
当我尝试使用标准希伯来语字体“arial.ttf”(当然还有希伯来语字符串)时,情况也是如此。如您所见,我已成功导入 _imaging,因此问题并不像 effbot.org 所建议的那样存在。
看来问题出在 Imagefont.truetype(...) 上。
任何帮助将非常感激
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来 PIL 是在没有 FreeType 支持的情况下构建的。安装 FreeType 开发文件并再次重建 PIL。
Sounds like PIL was built without FreeType support. Install the FreeType dev files and rebuild PIL again.
问题是 PIL 1.1.7 不能很好地与 Windows XP 配合使用。相同的代码在 Linux 或 XP 下运行良好,但使用 PIL 1.1.6
谜团已解
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