Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert image to ascii art
import sys; from PIL import Image; import numpy as np
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
if len(sys.argv) != 4: print( 'Usage: ./asciinator.py image scale factor' ); sys.exit()
f, SC, GCF, WCF = sys.argv[1], float(sys.argv[2]), float(sys.argv[3]), 7/4
img = Image.open(f)
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
img = np.sum( np.asarray( img.resize(S) ), axis=2)
img -= img.min()
img = (1.0 - img/img.max())**GCF*(chars.size-1)
print( "\n".join( ("".join(r) for r in chars[img.astype(int)]) ) )
@codedude

This comment has been minimized.

Show comment
Hide comment
@codedude

codedude Jun 16, 2016

Thanks, it works great ;)

codedude commented Jun 16, 2016

Thanks, it works great ;)

@stratosgear

This comment has been minimized.

Show comment
Hide comment
@stratosgear

stratosgear commented Nov 16, 2016

@piotrusin

This comment has been minimized.

Show comment
Hide comment
@piotrusin

piotrusin commented Nov 18, 2017

Thanks!

@Schizo

This comment has been minimized.

Show comment
Hide comment
@Schizo

Schizo Nov 29, 2017

you can do all one line when you fill it up with ;

Schizo commented Nov 29, 2017

you can do all one line when you fill it up with ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment