PIL draw.text()显示包含阿拉伯语连字的字符串作为两个单独的字形

时间:2016-08-17 15:30:27

标签: python string python-3.x python-imaging-library arabic-support

我有python代码。 “کم”是一个字符串,由两个字母ک和م组成。 但他们结合在阿拉伯语中。我把这个词给PIL库函数。但它是分别保存图像的两个字母。我怎样才能将它们结合起来。?

data2= "کم"    
draw.text(((W-w)/2,(H-h)/2),data2,(0,0,0),font=font)
draw = ImageDraw.Draw(img)
img.save("abc"+".png")

输出: 那是ک和م。

1 个答案:

答案 0 :(得分:2)

您可以使用python_arabic_reshaper库来正确编写文本。这是此库的github个回购。

安装库:

pip install --upgrade arabic-reshaper

然后像这样导入:

import arabic_reshaper

然后你可以像这样使用它:

text_to_be_reshaped = 'اللغة العربية رائعة'
reshaped_text = arabic_reshaper.reshape(text_to_be_reshaped)