Tuesday, April 24, 2007
HOWTO: JPEG to ASCII ART
I Was playing around with converting pictures of the kids to ASCII art ... you know the kind of pictures we used to make back in the stone age when all we had were text printers ....
Sorry, but you'll need to use Linux :)
First use djpeg to decode the jpeg to ppm format image file .... then use ppmtopgm, then pgmtopbm and finally pbmtoascii. pbmtoascii takes a size parameter of -1x2 or -2x4 meaning to map the character to a 1x2 or 2x4 pixel box. Obviously 1x2 gives better resolution but bigger pictures. This can all be accomplished with the single line:
/usr/bin/djpeg file.jpg | /usr/bin/ppmtopgm | /usr/bin/pgmtopbm | /usr/bin/pbmtoascii -2x4 > file.txt
Odds are the file will be huge ... start with a small file .... just a couple hundred pixels square ... a 400 X 600 pixel image will create a text file 200 columns by 150 lines long
Once you have your text file you may find you need to split it vertically to print. Use the "cut" comand to split into two files:
cat file.txt | cut -b-100 > file-left.txt
cat file.txt | cut -b101- > file-right.txt
this will create two files, each 100 columns wide ... you could split it as many times as you want, just change the rang on the "b" parameter, ( i.e. -b-66, -b67-133, -b-200 )
Then print the files on your favorite printer and tape the pages together.
Here is my avatar in ascii art format.
#posted by Rob Roschewsk @ 10:00 PM


