13

Is there any sort of utility I can use to convert an image to ASCII and then print it in my terminal? I looked for one but couldn't seem to find any.

user1447941
  • 3,675
  • 10
  • 29
  • 34
  • Note that there are some terminals that let you display an image without converting it to text. They just display an image. For example, the kitty terminal can do this. – Flimm Jul 07 '23 at 12:52

7 Answers7

10

A program called cacaview allows you to do this.

It is interactive, allowing you to pan, zoom, and change display modes.

Cacaview example

(Full size image)

Stecman
  • 2,890
  • 20
  • 18
  • 2
    `cacaview` opens a new window, it doesn't print out the image to the terminal, at least not in Ubuntu 21.10 – Flimm Nov 20 '21 at 18:55
  • Doesn't look like there's a command line option, but you can just execute clearing the DISPLAY environment variable to have it run in the current terminal: `DISPLAY= cacaview yourimage.jpg` – Stecman Nov 22 '21 at 01:59
  • Setting `DISPLAY=` does work, but it takes over the terminal screen, it doesn't print out to the terminal like `echo` would. – Flimm Nov 22 '21 at 07:19
  • See meduz's answer below - `img2txt` uses the same underlying code as `cacaview`, but prints to console like you're looking for – Stecman Nov 24 '21 at 03:13
6

more simply, you may use img2txt from the caca library (cacaview is an image browser and opens a new window, which is not what is asked here I guess);

For instance :

Screenshot

on macosx, you may use homebrew :

$ brew reinstall libcaca --with-imlib2

(imlib is used to convert from different formats)

Flimm
  • 136,138
  • 45
  • 251
  • 267
meduz
  • 3,903
  • 1
  • 28
  • 40
  • The default Homebrew install for libcaca (that is, without passing `--with-imlib2`) doesn't seem to be able to open any files. – bonh Oct 15 '14 at 03:27
5

Chafa

I like to use chafa.

chafa example.png

Screenshot

You can download Chafa from Chafa's website or from your favourite package manager, like APT:

sudo apt install chafa
Flimm
  • 136,138
  • 45
  • 251
  • 267
4

Try using the Google-Ninja before asking! I found cacaview and aview.

3

A high quality fast standalone conversion utility (provided you have a 256 color terminal) is pxl, available at https://github.com/ichinaski/pxl.

Aleksandr Dubinsky
  • 22,436
  • 15
  • 82
  • 99
Aguirre
  • 31
  • 1
2

Here's a utility that does this (with source code):

http://www.codeproject.com/Articles/10949/ASCII-Art-Generator

xxbbcc
  • 16,930
  • 5
  • 50
  • 83
0

Another alternative is to use the Ipython notebook: it is pretty good at doing what you ask for.

For bash: You have to prepend commands with a bang. For images: You may use the rich display system from ipython.

A screenshot of the result:

screenshot of the result

Complete answer in this post.

meduz
  • 3,903
  • 1
  • 28
  • 40