Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Show Images in terminal emulator

Display Images in Terminal Emulator

As seen here:

1. Installing needed stuff ...

Install packages w3m and some terminal emulator which supports images (urxvt, terminator, termite).

... using Arch Linux
sudo pacman -S w3m terminator

2. Make sure w3mimgdisplay binary is linked to directory your shell's $PATH

which w3mimgdisplay

It should show something like (in Arch Linux)

$ which w3mimgdisplay

Then it is alright. If the command doesn't output anything, you should search your system for w3mimgdisplay binary and link it:

find / | grep w3mimgdisplay

And if you installed in previous step it will show it's full path. Then you link it:

ln -s /CHANGE/THIS/WITH/PATH/w3mimgdisplay /usr/bin

3. Create a file with this script

# z3bra -- 2014-01-21

test -z "$1" && exit

FONTH=14 # Size of one terminal row
FONTW=8  # Size of one terminal column
COLUMNS=`tput cols`
LINES=`tput lines`

read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`

max_width=$(($FONTW * $COLUMNS))
max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt

if test $width -gt $max_width; then
height=$(($height * $max_width / $width))
if test $height -gt $max_height; then
width=$(($width * $max_height / $height))


tput cup $(($height/$FONTH)) 0
echo -e $w3m_command|$W3MIMGDISPLAY

4. Save the file as and make it executable:

chmod +x

5. Running

Make sure you are using a terminal emulator which supports images (urxvt, terminator, termite), and run the script passing a image file as argument:

./ my_image.png



This comment has been minimized.

Copy link

@ffuentese ffuentese commented Nov 5, 2020

It works! At least locally I managed doing it with rxvt-unicode in Ubuntu but I'm not being able to do it over ssh. Is there something I need to configure in SSH to make it work? (same terminal)

./ línea 20: test: -gt: se esperaba un operador unario
./ línea 24: test: -gt: se esperaba un operador unario
./ línea 31: /14: error sintáctico: se esperaba un operando (el elemento de error es "/14")

It's in Spanish but you get the idea. Unary operator expected. I get this same error in an incompatible console when trying the command locally (LXTerminal).


This comment has been minimized.

Copy link

@phanirithvij phanirithvij commented Nov 9, 2020

Better try using locate w3mimgdisplay first because for me find took a very long time and yet there were no results.
Also the image doesn't stay in the terminal for me after I switch tabs or scroll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment