diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-02-15 18:26:35 -0800 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-02-15 18:26:35 -0800 |
| commit | c3b34223ef6390ad2801edaa3e3b825c7df1cb98 (patch) | |
| tree | e71974dc33080d82fbeca80e7b3d8da28c57db0d /newimagefromjson.py | |
| parent | ca7216ef0777de4ea226c6d672c4862362f9e74c (diff) | |
asdfasdf
Diffstat (limited to 'newimagefromjson.py')
| -rw-r--r-- | newimagefromjson.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/newimagefromjson.py b/newimagefromjson.py new file mode 100644 index 0000000..25fdfcd --- /dev/null +++ b/newimagefromjson.py @@ -0,0 +1,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") |
