-
-
Save mkf/4ee7268b3fba11a43ab9 to your computer and use it in GitHub Desktop.
A simple script for displaying images in terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# z3bra -- 2014-01-21 | |
# modified by ArchieT 2015-07-04 | |
test -z "$1" && exit | |
test -z "$2" && x=5 | |
test -z "$2" || x=$2 | |
test -z "$3" && y=20 | |
test -z "$3" || y=$3 | |
test -z "$4" && scale=100 | |
test -z "$4" || scale=$4 | |
W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay" | |
FILENAME=$1 | |
FONTH=19 #14 # Size of one terminal row | |
FONTW=10 #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)) | |
width=$max_width | |
fi | |
if test $height -gt $max_height; then | |
width=$(($width * $max_height / $height)) | |
height=$max_height | |
fi | |
ulwidth=$(($width * $scale / 100)) | |
ulheight=$(($height * $scale / 100)) | |
w3m_command="0;1;$x;$y;$ulwidth;$ulheight;;;;;$FILENAME\n4;\n3;" | |
tput cup $(($height/$FONTH)) 0 | |
echo -e $w3m_command|$W3MIMGDISPLAY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment