$ python3 pix2term.py image.png
Since the output is text with special characters, you can generate an image once and display it later with cat:
$ python3 pix2term.py image.png > image_ansi $ cat image_ansi
This script depends on Python 3 and Pillow. Check Pillow’s documentation for detailed instructions, but as with any Python package, it boils down to pip install Pillow
or using your distro’s package manager.
This is a script that shows an image in a 256-color terminal emulator using ANSI escape codes. Each pixel is represented as a pair of spaces with a specific background color, which tries to match the original pixel color as closely as possible. In other words, you can create an image of up to $((COLUMNS/2))
pixels without line wrapping. Note that a character in a terminal emulator may not have an aspect ratio of 2:1, which means images might appear slightly stretched.
This script does not use the eight normal and eight bright colors from VT100 terminal emulators; instead, it uses the extended 216-color palette accessible via ESC[48;5;<n>m
. The reason behind this is that many people change these colors to use a custom color scheme, many of which sacrifice color variety for aesthetic reasons. As far as I’m aware, most people only change the main 16 colors, making the extended ones “safer” for images.
- Support true color terminals or actual image dislay protocols.
- Maybe add a better color matching algorithm.
Art on Wikimedia Commons | Art on Wikimedia Commons by Kasuga |