Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. import sys
  17. from PIL import Image
  18. from collections import defaultdict
  19. def main(img_name):
  20. img = Image.open(img_name)
  21. w,h = img.size
  22. symbols = defaultdict(str)
  23. symbols["transparent"] = " "
  24. characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  25. l = 0
  26. for i in range(h):
  27. k = 0
  28. for j in range(w):
  29. c = "".join(["{}{}".format(hex(x//16).split('x')[-1], hex(x%16).split('x')[-1]) for x in list(img.getpixel((j,i)))])
  30. d = " "
  31. if c[-2:] == "ff":
  32. cs = c[:-2]
  33. if cs not in symbols.keys():
  34. symbols[cs] = characters[0]
  35. characters = characters[1:]
  36. d = symbols[cs]
  37. print(d, end="")
  38. k += 1
  39. if k == 9:
  40. print("|", end="")
  41. k = 0
  42. print()
  43. l += 1
  44. if l == 9:
  45. for ww in range(int(w*1.1)+1):
  46. if (ww+1)%10 == 0:
  47. print("+", end="")
  48. else:
  49. print("-", end="")
  50. l = 0
  51. print()
  52. print("\nLEGEND")
  53. for k,v in symbols.items():
  54. print("{}: #{}".format(v,k))
  55. if __name__ == "__main__":
  56. #print(len(sys.argv))
  57. #print(sys.argv[1])
  58. if len(sys.argv) >= 2:
  59. img_name = sys.argv[1]
  60. else:
  61. img_name = "test.png"
  62. main(img_name)