build.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import PIL
  3. from PIL import ImageFont
  4. from PIL import Image
  5. from PIL import ImageDraw
  6. rootdir = "."
  7. fontsPerPage = 14
  8. pageWidth = 1000
  9. pageHeight = 1200
  10. curFontNumOnPage = 0
  11. curFontNum = 1
  12. curPageNum = 0
  13. defaultFont = ImageFont.load_default()
  14. print("Building tree in %s..." % (rootdir))
  15. for currentpath, folders, files in os.walk(rootdir):
  16. for file in files:
  17. ext = os.path.splitext(file)[1]
  18. if ext not in ['.ttf', '.otf']:
  19. continue
  20. if curFontNumOnPage == 0:
  21. img = Image.new("RGBA", (pageWidth, pageHeight), (255,255,255))
  22. yPos = (pageHeight / fontsPerPage * curFontNumOnPage) + 10
  23. filePath = os.path.join(currentpath, file)
  24. # print("Loading font %s" % (filePath))
  25. curFont = ImageFont.truetype(filePath, 26)
  26. draw = ImageDraw.Draw(img)
  27. draw.text((10, yPos), str(curFontNum) + ": " + filePath, (0,0,0), font=defaultFont)
  28. draw.text((10, yPos + 10),"Jackdaws love my big sphinx of quartz! 01234567890 []()", (0,0,0), font=curFont)
  29. draw.text((10, yPos + 40),"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ?$%", (0,0,0), font=curFont)
  30. curFontNumOnPage += 1
  31. curFontNum += 1
  32. if curFontNumOnPage >= fontsPerPage:
  33. img.save("page-%d.png" % (curPageNum))
  34. curFontNumOnPage = 0
  35. curPageNum += 1
  36. print("Completed %d fonts across %d files" % (curFontNum - 1, curPageNum))