summaryrefslogtreecommitdiff
path: root/newimagefromjson.py
blob: 5f62bd1d3d0ca80aa2d7256dbbbf6a770c45fb25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python2.7
import simplejson as json
from PIL import Image
import sys

f = open("myjson.json", 'r'); 
myjson = f.read();
f.close();

specs = json.loads(myjson);
img = Image.new('RGBA', (int(specs['width']), int(specs['height'])));

def boolToColor(boolean):
  if boolean:
    return (0,0,0,255);
  else:
    return (255,255,255,0)

pixels = img.load();
#for i in range(0, 9, 2):
#  dosomething(i)
for i in range(0, len(specs['matrix'])):
  for j in range(0, len(specs['matrix'][i])):
    pixels[j,i] = boolToColor(int(specs['matrix'][i][j]));

img.save("myimage.png", "PNG")