2017-12-18 26 views
0

2 문자 순열의 이미지를 생성하고 문자 결합에 arabic_reshaper을 사용하고 있습니다. 2 문자 2에 대한 순열은 4 개의 이미지를 생성하지만 arabic_reshaper은 t1 =
"Expected String or buffer" 오류를 생성합니다. 질문이 명확하지 않은지 문의하십시오."예상 문자열 또는 버퍼"

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