PIL draw.text() 将包含阿拉伯连字的字符串显示为两个单独的字形
PIL draw.text() is displaying string containing arabic ligature as two separate glyphs
我有 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")
输出:
那是 ک 和 م 。
您可以使用 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)
我有 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")
输出: 那是 ک 和 م 。
您可以使用 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)