summaryrefslogtreecommitdiff
path: root/newimagefromjson.py
blob: 25fdfcdbe1b595ef554d7a1df4555ea286725c8b (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
27
28
29
30
31
32
#!/usr/bin/python2.7
import simplejson as json
import Image

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

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

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

pixels = img.load();
for i in specs.matrix:
  for j in specs.matrix[i]:
    pixels[i,j] = boolToColor(specs.matrix[i][j]);


img = Image.new( 'RGBA', (500,500), "black") # create a new black image
pixels = img.load() # create the pixel map


for i in range(img.size[0]):    # for every pixel:
    for j in range(img.size[1]):
        pixels[i,j] = (255, 255, 255, 255) # set the colour accordingly

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