用Python在图像上编写Urdu文本

问题描述

希望这不会是重复的问题。 其实我是用PIL在Python上用图像写英文文本。动态选择文本,字体和图像。它工作正常。

现在我想对urdu文本做同样的事情,我具有所需的字体等,但是它不能将文本正确添加到图像中。

我缺少一些编码脚本等吗?

例如

enter image description here

解决方法

在我的情况下,您需要下载并使用与unicode兼容的字体arial

from PIL import Image,ImageFont,ImageDraw
image = Image.new("RGB",[320,320])
draw = ImageDraw.Draw(image)
a = u"Urdu text بے-اعیند ز "

font = ImageFont.truetype("C:\\Users\\Home\\Downloads\\arial-unicode-ms.ttf",14)
draw.text((50,50),a,font=font)
image.save("image.png")

urdu text

,
from PIL import Image,ImageDraw

from matplotlib import pyplot as plt
import numpy as np
import cv2

text_string = u'تصوير'

img = Image.new('RGB',(200,150))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('jameel.ttf',50)

draw.text((25,40),text_string,fill='white',font=font)

img.show()

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...