Skip to content

Instantly share code, notes, and snippets.

@ColtonPhillips
Created November 19, 2015 23:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColtonPhillips/f78e93dcbc0cef92bb5d to your computer and use it in GitHub Desktop.
Save ColtonPhillips/f78e93dcbc0cef92bb5d to your computer and use it in GitHub Desktop.
This converts a png into puzzlescript object format. It works for sizes that aren't typical for the editor
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