import os import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw rootdir = "." fontsPerPage = 14 pageWidth = 1000 pageHeight = 1200 curFontNumOnPage = 0 curFontNum = 1 curPageNum = 0 defaultFont = ImageFont.load_default() print("Building tree in %s..." % (rootdir)) for currentpath, folders, files in os.walk(rootdir): for file in files: ext = os.path.splitext(file)[1] if ext not in ['.ttf', '.otf']: continue if curFontNumOnPage == 0: img = Image.new("RGBA", (pageWidth, pageHeight), (255,255,255)) yPos = (pageHeight / fontsPerPage * curFontNumOnPage) + 10 filePath = os.path.join(currentpath, file) # print("Loading font %s" % (filePath)) curFont = ImageFont.truetype(filePath, 26) draw = ImageDraw.Draw(img) draw.text((10, yPos), str(curFontNum) + ": " + filePath, (0,0,0), font=defaultFont) draw.text((10, yPos + 10),"Jackdaws love my big sphinx of quartz! 01234567890 []()", (0,0,0), font=curFont) draw.text((10, yPos + 40),"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ?$%", (0,0,0), font=curFont) curFontNumOnPage += 1 curFontNum += 1 if curFontNumOnPage >= fontsPerPage: img.save("page-%d.png" % (curPageNum)) curFontNumOnPage = 0 curPageNum += 1 print("Completed %d fonts across %d files" % (curFontNum - 1, curPageNum))