Catpix — Where is the cat?

During my first project in Access Labs, I worked with my partner on building a Command Line application. I was thinking a lot about how to make our application look interesting. We already used ‘pastel’ to change the colors of the outputs in the terminal. We used ‘terminal-table’ to make a neat-looking history table where people can check their records. We also had ‘tty-prompt’ to put different symbols for menus. I was still not satisfied with the result. There was something missing here. What do people want to see when they click on the word ‘cat’?

A cat picture!

I found out about Catpix after that. Catpix is a gem that can bring graphics into the terminal. The image will not be the same like the original, it will be in a pixel image. Catpix has built in methods that you can use to resize, center, change the background color and the resolution of the image.

First of all, you need to install Catpix gem.

  • In Gemfile, add this line:
gem 'catpix'
  • Then in the terminal, execute this:
$ bundle
  • Or you can just install Catpix directly in the terminal:
$ gem install catpix

After setting up the gem, we create a ruby file to put the method there.

“On the inside, Catpix uses rmagick to read and scale images and the tco gem to map its colors to the extended 256 color palette in the terminal.” — Radek Pazdera

The hardest part is picking an image. It shouldn’t be complicated. For example I have an image of a carrot:

This carrot image is very basic with 2 colors base: orange and green. You know it’s a carrot right away. However, if I use this image to show carrots:

“Are you sure you are showing me carrots?”

That image has a lot of different colors and when you print it to the terminal, you probably have no idea what kind of image it is.

For the best result, we should use 8-bit images.

Pizza is a great image for Catpix!

“Ok, ok, I got it. Catpix prints images out to the terminal. But, where is the cat?”

“Well, here you go.”