KenSchutte.com
random pic random pic random pic random pic random pic
 

 

catimage : quick ascii display of images

Sometimes I've been on a text only connection and am trying to find a particular image file, but they're all named dsc01234.jpg or something, so I thought it would be helpful to have some image-to-ascii command line-based program - something that worked like the 'cat' command for images. I looked around a little, but didn't really find what I was looking for. (let me know if something exists) So, wrote up a crude version myself.

It's an incredibly simple little script, and therefore produces incredibly awful looking ascii images. There are probably simple ways to improve it, but I also don't want to sacrifice speed...

Usage


catimage [-w N] file1 [file2 file3 ...]');

Simply list one or more image files on the command line. There's an optional -w parameter to specifly the width (in number of characters) of the ascii output. The height is scaled to keep the original aspect ratio (assumes characters are in 1:2 ratio).

Basically all the common image formats are accepted as input because it uses Image::Magick to load the input.

Examples

Like I said, the quality of ascii imagesc is quite bad, so it's usefulness depends on the complexity of the image. Here's a a couple examples:

Good example: original and catimage output:
good example - orig good example - ascii

Not so good. You couldn't tell what it is from the ascii...
bad example - orig bad example - ascii

Installation

This is just a short perl script. Note you may need to change the first line of the file if your perl program is not at "/usr/bin/perl". Also you may want to do something like "chmod +x catimage; sudo mv catimage /usr/bin/". The main thing you need to get it working is that you need the perlmagick installed - perl module Image::Magick.

Implementation

I know nothing about ascii art and just did the quickest thing I could think of in a few lines of perl. I just resize it, convert to grayscale, and uniformly quantize to 5 levels and render as one of " .oO@".

Some simple image pre-processing I think could help (and wouldn't be hard with ImageMagick), but the problem is I'm looking for something very fast. I don't want to wait 5 or 10 seconds to see it. I'm often using it on 5 megapixel images, so processing on the original can be expensive.

If anyone knows something better or an easy way to improve it while keeping it fast, let me know.

Download

catimage

© 2008 Ken Schutte