【问题标题】:draw hebrew text to an image using Image module (python)使用 Image 模块(python)将希伯来文文本绘制到图像中
【发布时间】:2010-01-31 14:01:38
【问题描述】:

我正在尝试使用 Image 模块来制作带有希伯来字母的位图。 从外壳(空闲)打印时,我设法打印了希伯来语,但是当尝试将文本绘制到位图时,它会绘制一些 ascii 字母。

这是代码:

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()

任何帮助将不胜感激。

【问题讨论】:

    标签: python image draw


    【解决方案1】:

    试试a = u"אריאל"

    如果失败,请尝试PyCairo。它具有先进的排版处理,可能会更好。

    【讨论】:

      【解决方案2】:

      This site提到要绘制中文文本,他们必须指定字符串是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 字符串(而希伯来语与 ascii 相差甚远)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-29
        • 2018-12-24
        • 2012-05-06
        • 2011-11-29
        • 2018-11-22
        • 2019-02-26
        • 2011-09-02
        • 2013-11-08
        相关资源
        最近更新 更多