Archive for December, 2009

jp2a

I’m going to write about jp2a, a Linux utility that converts jpg images to ascii.  The problem is that my blog posts (when they happen) usually aren’t purely about technical topic.  I like to ramble on about random things.  So, I’m going to do that a bit and then talk about jp2a.

Oh, I thought of something: I’m eating a Banquet for lunch right now.  Boneless Pork Rib to be exact.  I noticed that after cooking it (haha, I mean heating) some of the sauce was still on the cellophane so I scraped it off with a fork so as to not miss that saucy-awesomeness.  I’m glad I did that.

Alright, I feel I have rambled enough, now on to jp2a.

If you didn’t get it already, jp2a stands for “jpg to ascii”.  They are hip and use ‘2′ to mean ‘to’.  Clever.

I wanted to email a picture of myself to my dad for possible use in a Christmas card he is going to make.  The problem was that I didn’t have the picture on my computer at the time.  I did have it on my server at home, though, so at least I could scp (transfer it via the intertubez) it to myself.  After finding the folder that the picture was in, I then had the problem of not knowing which picture of the thirty or so it was.  The folder was logically labeled, so that was good, but the actual images were just the standard IMG_[number].

Yet another roadblock was that my server doesn’t run a GUI, it is command-line only.  (Note how I’m not labeling that a “problem”, I prefer the challenge and awesomeness of a GUI-less server.)  That means that I couldn’t look at the image files without first transferring them to my computer.  That would take a while as [1] I’d have to transfer over the entire set of pictures and [2] the upload speed at my apartment isn’t stellar.

I decided to do some research and see if there was a utility that could produce an ASCII “art” representation of my images.  That would allow me to get a basic idea of what is in the image and I could do it all remotely.  Turns out there is and it’s called jp2a.

Using jp2a is pretty easy.  It includes a handy flag that will output the image in color on your terminal.  I’d almost say that a utility like this would be quite useless for what I’m doing with it here if one couldn’t output the ASCII in color.  One requirement is that the image is a jpg as it won’t work for other image formats.  (Once can use imagemagick and a pipe if they have to work with a non-jpg.)

So, quite simply, to run jp2a one types:

jp2a --color [image name]

Now for some examples.  Here is the picture that I was looking for:

that's me!

This is what it looks like when jp2a is ran on it:

that's me in gigabitz

As you can see, it does a pretty decent job of representing what the image looks like!

One last thing: I had to run this command on all the pictures in the folder.  jp2a doesn’t label the image when it prints out, so using * as the input value isn’t too helpful because you don’t know what the name of the file is that is being displayed.  I found and edited a quick bash script to output the name before the picture as well as run jp2a on all jpg files in the current directory:

#!/bin/bash
for file in `dir -d *JPG` ; do
    echo $file
    /usr/bin/jp2a "$file" --colors --width=100
done

Yeah, yeah, it could be more advanced, but it did what I want.

So there you have it.  A blog post and an informative one at that.  Plus, you got to see my pretty face, always a plus.

No Comments »

william on December 17th 2009 in Banquet, Puters