Last active
August 29, 2015 14:07
-
-
Save szolotykh/b3fcda9483560c87bbe5 to your computer and use it in GitHub Desktop.
PyPNG: Map to PNG function (array to PNG)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://pythonhosted.org/pypng/ex.html | |
import png | |
import time | |
def map2png(name, amap, w, h): | |
amap2 = list(amap) | |
for i in range(len(amap2)): | |
if amap2[i] == 100: | |
amap2[i] = 255 | |
if amap2[i] == -1: | |
amap2[i] = 100 | |
l = [] | |
for i in range(0, len(amap2), w): | |
l += [tuple(amap2[i:i+w])] | |
f = open(name+".png", 'wb') | |
w = png.Writer(w, h, greyscale=True) | |
w.write(f, l) | |
f.close() | |
#m = [-1,0,0,0,0,100] | |
#map2png("map_"+time.strftime("%H:%M:%S"),m, 3, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment