2017-12-18 7 views
0

私は2文字の順列の画像を生成しており、文字の結合にはarabic_reshaperを使用しています。 2文字の2の置換は4つのイメージを生成しますが、arabic_reshaperはエラー"Expected String or buffer"を生成しています。t1 = arabic_reshaper.reshape(word).
質問が不明な場合は質問してください。"期待される文字列またはバッファ"

from bidi.algorithm import get_display 
import PIL.Image, PIL.ImageFont, PIL.ImageDraw 
import arabic_reshaper 

unicode_text = u"\u06F1"+ u"\u06CC"+ u"\u06A9" 
list_of_letters = list (unicode_text) 
folder = 1 
n=2 
for i in range(1,n+1): 
    for word in itertools.permutations(list_of_letters,i): 
     print word 
     t1 = arabic_reshaper.reshape(word) 
     print t1 
     img= PIL.Image.new("L", (200, 200)) 
     draw = PIL.ImageDraw.Draw(img) 
     font = PIL.ImageFont.truetype(r"C:\Users\arabtype.ttf", 40) 
     t2 = get_display(t1)  
     print t2# <--- here's the magic <--- 
     draw.text((10,50), ' ' + t2, fill=220, font=font) 
     img.show() 

答えて

1

問題は、itertools.permutationsがタプルを生成することです。

文字列に変換する必要があります。このようなもの:

for word in itertools.permutations(list_of_letters,i): 
    word = u''.join(word) 
    print word 
関連する問題