cleanin up coding conventions
This commit is contained in:
@@ -2,50 +2,60 @@
|
||||
import sys
|
||||
import scipy.misc
|
||||
import numpy as n
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser
|
||||
|
||||
|
||||
def png2asc(inFile):
|
||||
im=scipy.misc.imread(inFile)
|
||||
im = scipy.misc.imread(inFile)
|
||||
|
||||
for r in im:
|
||||
for c in r:
|
||||
if c>127:
|
||||
char="X"
|
||||
char = "X"
|
||||
if c<128:
|
||||
char="."
|
||||
char = "."
|
||||
if c==0:
|
||||
char=" "
|
||||
char = " "
|
||||
sys.stdout.write(char)
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.write("\n")
|
||||
|
||||
def asc2png(inFile,outFile):
|
||||
def asc2png(inFile, outFile):
|
||||
reader = open(inFile,'r')
|
||||
coords=[]
|
||||
max_c=0
|
||||
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))
|
||||
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 )
|
||||
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]
|
||||
|
||||
im[c[0], c[1]] = c[2]
|
||||
|
||||
scipy.misc.imsave(outFile, im)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser=ArgumentParser(description="Convert image to ascii, or ascii to image. If only input is defined, it is assumed as image (PNG).")
|
||||
parser.add_argument('input', action="store")
|
||||
parser.add_argument('output', action="store", nargs='?')
|
||||
opts=parser.parse_args()
|
||||
parser = ArgumentParser(
|
||||
description = "Convert image to ascii, or ascii to image. If only input is defined, it is assumed as image (PNG)."
|
||||
)
|
||||
parser.add_argument(
|
||||
'input',
|
||||
action = "store"
|
||||
)
|
||||
parser.add_argument(
|
||||
'output',
|
||||
action = "store",
|
||||
nargs = '?'
|
||||
)
|
||||
opts = parser.parse_args()
|
||||
|
||||
if opts.output==None:
|
||||
png2asc(opts.input)
|
||||
else:
|
||||
asc2png(opts.input,opts.output)
|
||||
if opts.output == None:
|
||||
png2asc(opts.input)
|
||||
else:
|
||||
asc2png(opts.input, opts.output)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user