以下代码为每个字符在每个文件夹中创建一个文件夹和一个图像,因此我有36个字符的36个文件夹。字符是不同的字体到目前为止,我已经使用4字体,我一个接一个地粘贴路径,但现在我有近200种字体,所以我尝试for loop
检索每个font
,但它没有&# 39;输出任何东西。代码打印所有字体名称但不创建任何图像
主文件夹中共有36个文件夹。
Dataset:\(36 folders)
character(1):\
200 images for 200 fonts
character(2):\
200 images for 200 fonts
...............
character(36):\
200 images for 200 fonts
list_of_letters = list (unicode_text)
folder = 1
n=1
i=0
for word in itertools.permutations( list_of_letters,n):
char = u''.join(word)
t1 = arabic_reshaper.reshape(char)
W,H= (100, 100)
img= PIL.Image.new('RGBA', (W, H), (255, 255, 255),)
draw = PIL.ImageDraw.Draw(img)
# font = PIL.ImageFont.truetype( r"C:\Users\Sumayyah\Downloads\arabic-typesetting\arabtype.ttf", 40)
path=r'E:\Dummy\fonts'
directory = os.fsencode(path)
for file in os.listdir(directory):
filename = os.fsdecode(file)
if filename.endswith(".ttf"):
print(os.path.join(path, filename))
continue
for i in range(158):
draw.font = PIL.ImageFont.truetype(os.path.join(path, filename), 44)
t2 = get_display(t1)
w, h = draw.textsize(t2)
draw.text(((W-w)/2,(H-h)/2),t2, fill="#000000")
path = 'E:\Dummy\Old\\'+ str(folder)
if not os.path.exists(path):
os.makedirs(path)
img.save(path + '\\' + char+str(i)+'.png', "PNG")
i+=1
folder += 1