ASCII image converting

Other programs allow one to automatically convert an image to text characters, which is a special case of vector quantization. A method is to sample the image down to grayscale with less than 8-bit precision, and then assign a character for each value. Such ASCII art generators often allow users to choose the intensity and contrast of the generated image based on depth, sharpness, and ratio.

Still, images or movies can also be converted to ASCII on various UNIX and UNIX-like systems using the AAlib (black and white) or libcaca (color) graphics device driver, or the VLC media player or MPV under Windows, Linux, or macOS; all of which render the screen using ASCII symbols instead of pixels.

There are also a number of smartphone applications, such as ASCII cam for Android, that generate ASCII art in real-time using input from the phone's camera. These applications typically allow the ASCII art to be saved as either a text file or as an image made up of ASCII text.

Converting process

ASCII art image conversion basically consists of three steps :

1. Resize the image.

2. Converting our picture into gray colors (black & white).

3. Mapping each pixel to a given character depending on the grayscale value from the darker to the brighter " .',;:clodxkO0KXNM@".

Example :

We're going to convert this image to ASCII using the “jp2a” module in Linux terminal :

bird

install it with this command :

sudo apt install jp2a

then type jp2a followed by the path of the image (.jpg) or (.png), and you can add some edit options like --color to colorize the ASCII image, --size=500x500 to resize the image, and more options that you can find by typing "man jp2a".

jp2a ./images/bird.jpg --chars=" ...',;:clodxkO0KXNM@"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,,,,,,,,,,,,,,,,,,,
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,,,,,,,,,,,,
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,,,,,
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:cclooodddoollc:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:cldxkO00K0KK0000Okkkkxdol:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;:;:::;;;::;::::::::::::::::::::::::::::lxk0KKKKKKK000OOOOkkxxdodddoddoc:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:::::::::::::::::::::::::::::::::::::::::::::oOKKXKKKKK00OOkxxdl;...,;clcloooodolc::;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:::::::::::::::::::::::::::::::::::::::::ldOKKKKKK00Okkkxdolol, .  ...,:::ccllollllc:;;;;;;;;;;;;;;;;;;;;;;;;;;;
:::::::::::::::::::::::::::::::::::::::oOKKK0000OOkxddxxxxkkxxl,....',:clc:::ccccclc:;,;:;;;;;;;;;;;;;;;;;;;;;;;
:::::::::::::::::::::::::::::::::ccldk0K00OkkOOkkkxdxkkkkkkkkxdoollccllllccccc:::cc::;,',;:::::::;;;;;;;;;;;;;;;
::::::::::::::::::::ccccclllllllclok0OOOOkxxkkkxxxxdxxkxkkxxkxddddoollccccccccclccc::;,',';:::::::::::;:;;;;;;;;
:::::::::::::::cloolloocccc::::cc:cooxkxdooxxkxddxdoxxxkxxxxxxddddoooolllllllllllllcc::;,'.,::::::::::::::::::::
::::::::::::codolcccc;,,,,'',;::;;::c::::cccc:;;;;::ccloodddxxxxxxddooooooooooolllccc::;,'..,:::::::::::::::::::
::::::::::coxoc:;;,,,',,,,''''''''''''''''....,;cccclooollcoxxxxxddoddddddooolollccc:::;;'...;::::::::::::::::::
:::::::::cddc;;,,''...........'''''''''''',:ldkkxxkkkkkkkxxO000Okxddddddoolllllllcc::::;,'...'::::::::::::::::::
:::::::::ooc;,'............'''''''''''''',:lc:llllooodddddxxxkkkxddddoooollclllccc:::;;,'....'::::::::::::::::::
::::::::coc;'............'',,;;;;;;;:::::::;;;::;:::coodddddxxxddddddoooollccccc::::;;;,'....'::::::::::::::::::
ccc:cccccl:;,,,'.....',;:::cccccccccccccc:::::::::::looooooooddddddoododooollccccccc::;,,'...'::::::::::::::::::
cccccccccccccccccccccccccccccccccccccccccccc::;;:::cclooooloodddddddddddddoooolldooolc::;'...'::::::::::::::::::
ccccccccccccccccccccccccccccccccccccccccccccccc;;;::coodddxxxkkkkkxxxxxxxddddooodxddolc:;'...'::::::::::::::::::
cccccccccccccccccccccccccccccccccccccccccccccccc;,;:lddxxxxkkOOOOOOOkkkkkxxxxxddxkxxdoc:;''..,::::::::::::::::::
cccccccccccccccccccccccccccccccccccccccccccccccc:,;:oxkkOOO000000000000OOOOOOkkkOOOkdoc:,''..,ccccc:c:::::::::::
cccccccccccccccccccccccccccccccccccccccccccccccc:;;:ok000KKKKKKKKKKKKK0000000OOOOOkkdlc;,'''';ccccccccccc:ccc:::
cccccccccccccccccccccccccccccccccccccccccccccccc;;:lOKKKKKKKXXXXXKKKKKKKKKK000OOkkxddlc;,'''':cccccccccccccccccc
ccccccccccccccccccccccccccccccccccccccccccccccc:;:lOKKKXXXXXXXXXXXXXKKKKKKK00OOkkkxdoc:,'''''ccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccccccl::cd0KXXXXXXXXXXXXXXXXKKKK0000OOkkxddolc;,'''';ccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccccclc:ckKXXXXXXXXXXXXXXXXXXKKKK0000OOkkddolc:,,''',cccccccccccccccccccc
cccccccccccccllllllllllllllllllllllllllllllll:lOKXXXXXXXXXXXXXXXXXKKKKKK000OOOkxdolc:;,,''':cccccccccccccccccccc
llllllllllllllllllllllllllllllllllllllllllllcdKXXXXXXXXXXXXXXXXXXXKKKKKK00OOkkxddllc:,,,'''ccccccccccccccccccccc
lllllllllllllllllllllllllllllllllllllllllldlxKXXXXXXXXXXXXXXXXXXXXKKKKK00OOkkxxdoll:;,,,,':ccccccccccccccccccccc
llllllllllllllllllllllllllllllllllllllllldoxKXXXXXXXXXXXXXXXXXXXXKKKKKK00OOkxxxdool:;,,'';cccccccccccccccccccccc
lllllllllllllllllllllllllllllllllllllllllxkXXXXXXXXXXXXXXXXXXXXXXKKKK000OOkkxxxddol:;,,'':llllclcccccccccccccccc
lllllllllllllllllllllllllllllllllllllllldOXXXXXXXXXXXXXXXXXXXXXXKKKKKK000OOOOkkxdollc:,''clllllllllccccccccccccc
llllllllllllllllllllllllllllllllllllllld0XXXXXXXXXXXXXXXXXXXXXXXXKKKKK00000OOOkkkxxddlc;,;llllllllllllllcccccccc
lllllllllllllllllllllllllllllllllllllll0KXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKK000000OOOOOkkkkxdolllllllllllllllllllll
llllllllllllllllllllllllllllllllllllllxKXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKK000K00000000OOkdolllllllllllllllll
lllllllllllllllllllllllllllllllllllllo0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKK00000OOOkdolllllllllllll
lllllllllllllllllllllllllllllllllllllxKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXKXXXKKKKKKKKKKKKK000OOOOOOkdolllllllll
lllllllllllllllllllllllllllllllllllooOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKK000OOOOO0OOOkdollllll

Videos converting

Converting videos to ASCII has the same idea as images by converting each frame in the video. In this case, we are using the “ascii-vp” python module in the terminal to show a video as ASCII characters. If you want more options and informations, find it in this link : github.com/malkiAbdoo/ascii-vp

install it with this command :

pip3 install asciivp

to use it, just type "asciivp" following by the path or URL of the video, and you can add options like the --chars and --size that you can find in the previous link.

asciivp video.mp4

or you can use a youtube URL:

asciivp "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley"

GIF to ASCII

We are going to use a python module called “asciisciit” to convert a GIF to ASCII and render it back to a GIF, find more information in this link : github.com/derricw/asciisciit

install it with pip command :

pip install asciisciit

then convert the GIF by typing "asciisciit" followed by the path GIF and the path of the ASCII render and the font size after -p.

asciit ./gif/giphy.gif ascii_render.gif -p 8 video