font-borderremover.py 958 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # Take an font image file, split it appart and recombine it without
  3. # the 1px border around each glyph
  4. import os
  5. import sys
  6. import PIL
  7. from PIL import Image
  8. for filename in sys.argv[1:]:
  9. img = Image.open(filename)
  10. glyphs = []
  11. cols = img.size[0] // 22
  12. rows = img.size[1] // 24
  13. # 352x528
  14. for y in range(0, rows):
  15. for x in range(0, cols):
  16. glyph = img.crop((x*22 + 1,
  17. y*24 + 1,
  18. x*22 + 22 - 1,
  19. y*24 + 24 - 1))
  20. glyphs.append(glyph)
  21. out = Image.new(img.mode, (cols * 20, rows * 22))
  22. for y in range(0, rows):
  23. for x in range(0, cols):
  24. glyph = glyphs[x + cols * y]
  25. out.paste(glyph, (x * 20, y * 22))
  26. out_filename = os.path.join("/tmp/", os.path.basename(filename))
  27. print("writing {}".format(out_filename))
  28. out.save(out_filename)
  29. # EOF #