【问题标题】:Write Unicode Text On Image In Python Pillow?在 Python Pillow 中的图像上写 Unicode 文本?
【发布时间】:2020-11-11 02:40:15
【问题描述】:

我正在尝试在枕头图像上写旁遮普语/Gurmukhi 文本它没有完全工作。 这是我的代码:

from PIL import Image, ImageDraw, ImageFont

#configuration
font_size=36
width=500
height=100
back_ground_color=(255,255,255)
font_size=36
font_color=(0,0,0)

# Unicode For "ਸ੍ਰੀ" is "\u0a38\u0a4d\u0a30\u0a40"
unicode_text = u"ਸ੍ਰੀ"

im  =  Image.new ( "RGB", (width,height), back_ground_color )
draw  =  ImageDraw.Draw ( im )
unicode_font = ImageFont.truetype("raavi.ttf", font_size)
draw.text ( (10,10), unicode_text, font=unicode_font, fill=font_color )

im.save("text.jpg")

但是输出是这样的:

此外,当我们在终端中使用print(u"ਸ੍ਰੀ") 时,它将返回与输出图像中显示的相同的文本。但是当我们从终端复制该文本并将其粘贴到其他地方时,输出是正确的ਸ੍ਰੀ

【问题讨论】:

  • 也许你没有得到你想要的字体?

标签: python unicode python-imaging-library


【解决方案1】:

我找到了解决方案。 这是因为 Python 将 ਸ੍ਰੀ 呈现为四个字符。 我创建了一个包和 TTF 文件,以便在图像和 Pdf 上正确显示单词。

退房:- pi7gurmukhi

Correct Output

【讨论】:

  • 这看起来也是其他印度语言的常见问题。你能帮助其他字体/语言需要做什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 2014-09-04
  • 2013-12-20
  • 2022-08-07
  • 2020-05-05
  • 2013-05-13
相关资源
最近更新 更多