ICat

Regular picture of Garfield next to one converted to ASCII characters.
Year started: 2023

Have you ever wanted to know what an image looks like without having to leave the terminal? Well you're in luck! Now you can "cat" images with this utility called ICat (short for image cat)! ICat works by reading images and converting them to ASCII text. Images printed to the terminal are displayed in greyscale with 5 colors.

Languages and Libraries used:
View Code Source

How it was coded

My initial plan to code ICat was to use pure C++. However, in order to support multiple image formats such as PNG, Bitmap, Jpeg, etc I would need to import multiple image decoding libraries, causing the development to be very slow. Additionally, I realized I wouldn't gain a significant improvement in speed. I noticed in my experience in working with images in Python that Python wasn't slow for the most part. So I went with Python in having it handle the code involving image manipulation.

The next challenge was determining how to have ICat be executable in any directory and have an installation exectuable allowing this to happen. I discovered that this was easy to do in Bash, so I decided that Bash would handle the installation and the user interface for running the program.

I had previous knowledge from another Python project that I could open an image, convert it to black and white, and then convert it into a NumPy 2D array. With that knowledge I knew I could iterate through the array and print shaded ascii block characters (█, ▓, ▒, and ░) depending on the current number indexed. These in essence would be "pixels" displayed on the terminal.

So I started coding ICat and made some tests, and to my surprise I was in fact able to display images on my terminal and actually recognize (mostly) what I was looking at. Since I was using the Pillow Python library to open images and convert them to black and white, I realized I could apply a sharpening filter, an invert filter, and more to images, so I added args to ICat that would allow users to manipulate the image a little bit so that they could better see what they were looking at.

I went even further with improving ICat by giving an option to install all the needed Python libraries when users install ICat itself. I even added settings that users could change so that ICat would print images in the right aspect ratio if their terminals used monospace font or not. I also made a setting where images printed would not display inverted if they were printed on a light colored terminal.

Example Prints

Matrix of binary numbers converted into ASCII text.Image of Jeff the killer converted into ASCII text.

Garfeild print.