25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

26 lines
582 B

  1. #!/usr/bin/python3
  2. import sys
  3. from PIL import Image
  4. '''
  5. Converts a PNG into a palette compatible
  6. with aptdec. Requires PIL:
  7. pip3 install Pillow
  8. '''
  9. if len(sys.argv) == 1:
  10. print("Usage: python3 {} filename.png".format(sys.argv[0]))
  11. exit()
  12. image = Image.open(sys.argv[1])
  13. pixels = image.load()
  14. sys.stdout.write("char palette[{}][3] = {{\n \"".format(image.size[1]))
  15. for y in range(1, image.size[1]+1):
  16. sys.stdout.write(''.join('\\x{:02x}'.format(a) for a in pixels[0, y-1]))
  17. if(y % 7 == 0 and y != 0):
  18. sys.stdout.write("\",\n \"")
  19. print("\"\n};")