diff --git a/chr2pix b/chr2pix new file mode 100755 index 0000000..ddd49f9 --- /dev/null +++ b/chr2pix @@ -0,0 +1,49 @@ +#!/usr/bin/python +import sys +import scipy.misc +import numpy as n + +def png2asc(inFile): + im=scipy.misc.imread(inFile) + + for r in im: + for c in r: + if c>127: + char="X" + if c<128: + char="." + if c==0: + char=" " + sys.stdout.write(char) + sys.stdout.write("\n") + +def asc2png(inFile,outFile): + reader = open(inFile,'r') + coords=[] + max_c=0 + for r,row in enumerate(reader): + for c,col in enumerate(row): + if col not in (' ','\n'): + if col==".": + coords.append((r,c,127)) + else: + coords.append((r,c,255)) + max_c=max(max_c,c) + im=n.zeros( (r,max_c-1), dtype=n.uint8 ) + for c in coords: + im[c[0],c[1]]=c[2] + + scipy.misc.imsave(outFile, im) + +if len(sys.argv)==1: + print("Arguments:") + print(" [png image file] : prints ascii in stdout") + print(" [text file] [png image file] : convert characters to pixels in image") + sys.exit(0) +inFile = sys.argv[1] +if inFile.lower().endswith('.png'): + png2asc(inFile) +else: + asc2png(inFile,sys.argv[2]) + +