Skip to content

Instantly share code, notes, and snippets.

@benthetechguy
Created June 1, 2023 04:58
Show Gist options
  • Save benthetechguy/e31fb541c49a57f5f44c4c7cca79770c to your computer and use it in GitHub Desktop.
Save benthetechguy/e31fb541c49a57f5f44c4c7cca79770c to your computer and use it in GitHub Desktop.
# Quick and dirty script to turn a 16x16 image into 8-bit color values.
# Made to create icons for use in a CHRP script. Debian logo example:
# 0000000000C1C1C1C5C1C5EE00000000
# 00000000C1C1C1C1C1C1C1C1C1000000
# 000000C1C1C1C1000000C5C1C1C10000
# 0000C1C1C1C10000000000C1C1C10000
# 0000C5C1C10000C1C1C1C100C1C10000
# 0000C1C1000000C50000C900C1C50000
# 0000C1C50000C1C10000C500C1C10000
# 0000C1000000C1C10000C900C1C50000
# 0000C1C10000C5C100C500C1C5000000
# 0000C1C50000C9C5C1C1C1C1C1000000
# 0000C1C1EE0000C1C1C1C10000000000
# 0000C1C1C10000000000000000000000
# 000000C1C10000000000000000000000
# 00000000C1C100000000000000000000
# 00000000C1C1C5000000000000000000
# 000000000000C1C1C100000000000000
from PIL import Image
from more_itertools import chunked
img = Image.open('image.png')
pixels = []
for i in range(0, 16):
for j in range(0, 16):
pixels.append(img.getpixel((j, i)))
values = []
for pixel in pixels:
red = format(int((pixel[0] * 8) / 256), 'b').zfill(3)
green = format(int((pixel[1] * 8) / 256), 'b').zfill(3)
blue = format(int((pixel[2] * 4) / 256), 'b').zfill(2)
values.append(format(int(red + green + blue, 2), 'X').zfill(2))
for chunk in chunked(values, 16):
print(''.join(chunk))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment