Created
July 31, 2025 06:02
-
-
Save hornc/9ce622c0281efd21636c955770a48cd1 to your computer and use it in GitHub Desktop.
pixel art to numeric text grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
from PIL import Image | |
# opens a limited palette | |
# pixel art image and outputs | |
# a 0-9 digit grid | |
# + palette | |
if __name__ == '__main__': | |
fname = sys.argv[1] | |
img = Image.open(fname) | |
w, h = img.size | |
colors = {} | |
for y in range(h): | |
for x in range(w): | |
r,g,b,a = img.getpixel((x,y)) | |
col = f'{r},{g},{b}' | |
if a == 0: | |
print('0', end='') | |
elif col in colors: | |
print(colors[col], end='') | |
else: | |
colors[col] = len(colors) + 1 | |
print(colors[col], end='') | |
print() | |
print('\n', colors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment