用于检索python zero outpu中字体的Forloop

2024-06-08 07:56:45 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码为每个字符在每个文件夹中创建一个文件夹和一个图像,所以我有36个文件夹,其中包含36个字符。字符有不同的字体到目前为止,我已经使用了4种字体,我是粘贴路径一个接一个,但现在我有近200种字体,所以我尝试了for loop检索每个font,但它没有输出任何东西。以下代码打印所有字体名称,但不创建任何图像。
主文件夹中总共有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

Tags: pathin文件夹forpilos字体fonts