Skip to content

Instantly share code, notes, and snippets.

@vtols
Created January 28, 2013 17:38
Show Gist options
  • Save vtols/4657460 to your computer and use it in GitHub Desktop.
Save vtols/4657460 to your computer and use it in GitHub Desktop.
from PIL import Image, ImageDraw
import sys
infile = sys.argv[1]
f = file(infile)
w, h = map(int, f.readline().split()[2::3])
lines = f.readlines()
x = lines[0][0]
im = Image.new('RGB', (w, h), (0, 0, 0))
draw = ImageDraw.Draw(im)
print h, w
for i in range(0, h):
for j in range(0, w):
g = "white" if lines[i][j] == x else "black"
draw.point((j, i), fill=g)
im.save(infile + '.png', 'PNG');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment