Created
June 4, 2016 07:34
-
-
Save ColtonPhillips/e86a77a824f16e1c100ad703ee041880 to your computer and use it in GitHub Desktop.
Turn PNG files into PUZZLESCRIPT format quickly
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
def addUnique(l,item): | |
if item not in l: | |
l.append(item) | |
return l | |
from PIL import Image | |
import sys | |
im = Image.open(sys.argv[1]) | |
pix = im.load() | |
#first create the legend | |
# Creates a list containing 5 lists initialized to 0 | |
out_l_l = [[0 for x in range(im.size[0])] for x in range(im.size[1])] | |
col_set = [] | |
for j in range(im.size[0]): | |
for i in range(im.size[1]): | |
r, g, b, a = pix[i,j] | |
curPixel = '#%02x%02x%02x' % (r, g, b) | |
if a != 0: | |
addUnique(col_set, curPixel) | |
line = "" | |
for item in col_set: | |
line += item + " " | |
print line | |
for j in range (im.size[0]): | |
line = "" | |
for i in range (im.size[1]): | |
r,g,b,a = pix[i,j] | |
if (a == 0): | |
line += "." | |
else: | |
curPixel = '#%02x%02x%02x' % (r, g, b) | |
line += str(col_set.index(curPixel)) | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi is there a gui/way to get image into https://www.puzzlescript.net format (I dont know py)?