Showing Black and White Icons as Text on Terminal

The result of the script.

I enjoy competitive programming so I spend a lot of time on Hackerrank solving various problems. One day I tried to solve this problem and it got me thinking about text formatting when running scripts on terminal.

With that problem in my mind and thinking that back-end development didn’t need to be visually uninteresting I created this script. It receives as input the path to a black and white icon on your computer, image width, image height, and it outputs that icon on the terminal using ‘#’ and whitespaces.

How it Works

Turning the image into a 2D numpy array

Then, I iterated through the array to create a new one. If the number on arr[i][j] was 0, the new array would have a whitespace on the ith row and jth column. If the number was not zero, I’d fill the new array with a ‘#’ symbol.

Genarating the 2D array of characters that will represent the image

After that, I printed the array generated.

My printing function

Since this was just a test to learn a bit about image processing I didn’t plan a lot to write this script, but in the future I intend to make a lib out of this to make it useful for everyone and every project, and I’d love some help!

Let’s talk on LinkedIn.

Computer Scientist & Data Analyst & Currently looking for a job.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store