You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

img2gradient.py 749 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python3
  2. import sys
  3. from PIL import Image
  4. """
  5. Converts a PNG into a gradient compatible
  6. with aptdec. Requires Pillow:
  7. pip3 install Pillow
  8. """
  9. if len(sys.argv) == 1:
  10. print("Usage: {} filename.png".format(sys.argv[0]))
  11. exit()
  12. image = Image.open(sys.argv[1])
  13. pixels = image.load()
  14. if len(pixels[0, 0]) != 3:
  15. print("Image must be RGB")
  16. exit()
  17. if image.size[0] != 1:
  18. print("Image must be 1px wide")
  19. exit()
  20. print("uint32_t gradient[{}] = {{\n ".format(image.size[1]), end="")
  21. for y in range(image.size[1]):
  22. print("0x" + "".join("{:02X}".format(a) for a in pixels[0, y]), end="")
  23. if y != image.size[1] - 1:
  24. print(", ", end="")
  25. if y % 7 == 6:
  26. print("\n ", end="")
  27. print("\n};")