[英]Error “expected string or buffer”
我正在生成2个字符排列的图像,并使用arabic_reshaper
来加入字符。 2个字符的2置换将生成4个图像,但是arabic_reshaper
在t1 = arabic_reshaper.reshape(word).
产生错误"Expected String or buffer"
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()
问题是itertools.permutations
生成一个元组。
您需要将其转换为字符串。 像这样:
for word in itertools.permutations( list_of_letters,i):
word = u''.join(word)
print word
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.