Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

stitchify.py 1.0KB

6 anos atrás
1234567891011121314151617181920212223242526272829303132333435363738
  1. """ Converts pixel-art images into cross-stitch patterns.
  2. This tool assumes that 1px = 1 stitch.
  3. TODO:
  4. * Accept image name from command line.
  5. * Change characters to symbols for ease of reading.
  6. * Expand number of symbols.
  7. * Create image from symbolized pixels instead of just printing to screen.
  8. * Add grid lines and edge labels to image.
  9. * Add legend to image, based on the `symbols` dictionary.
  10. * Correspond hex colors to floss colors, where possible.
  11. * (Maybe) add stitch count for each color.
  12. * (Maybe) add GUI.
  13. """
  14. __author__ = "Noëlle Anthony"
  15. __version__ = "0.1.0"
  16. from PIL import Image
  17. from collections import defaultdict
  18. img = Image.open('test.png')
  19. w,h = img.size
  20. symbols = defaultdict(str)
  21. characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  22. for i in range(h):
  23. for j in range(w):
  24. c = "".join(["{}{}".format(hex(x//16).split('x')[-1], hex(x%16).split('x')[-1]) for x in list(img.getpixel((j,i)))])
  25. d = " "
  26. if c not in symbols.keys():
  27. symbols[c] = characters[0]
  28. characters = characters[1:]
  29. d = symbols[c]
  30. print(d, end="")
  31. print()