DEV Community

Stefanos Kouroupis
Stefanos Kouroupis

Posted on

Drawing images on the terminal

Lately, I've been experimenting with stable diffusion, and it has proven to be a captivating experience. However, if you're using a version that lacks a webUI, you're required to repeatedly switch back to a graphical user interface to view the output.

If you have used stable diffusion locally, especially for generating portraits you will know that it produces a lot of images with two heads, or multiple limbs, long necks etc. No matter how good your prompts are if you move away from producing square images of a certain size, it's something you get a lot. So I wanted to be able to quickly inspect the images from the terminal.

If you've worked with stable diffusion on a local setup, particularly for generating portraits, you're likely familiar with the phenomenon of resulting images featuring multiple heads, limbs, elongated necks, and more. Regardless of the quality of the prompts, if you opt out from generating square images of specific dimensions often results in such artifacts. Therefore, I had to find a way to examine the images directly from the terminal.

So, I wrote a small Rust application that converts images into coloured text. The added benefit is that it functions seamlessly in both Windows PowerShell and Linux terminal environments.

https://github.com/elasticrash/image-peek

The underlying logic of the application is relatively straightforward:

  • Get the dimensions of the image
  • Get the size of the terminal
  • Scale down the image so it can fit in our current terminal
  • Calculate the color of the character in relation to the image.
  • Print the character

Image description

Image description

Top comments (0)