dotfiles

andersuno dotfiles
git clone git://git.andersuno.nu/dotfiles.git
Log | Files | Refs | README

imgt (796B)


      1 #!/bin/bash
      2 #
      3 # Based on script by z3bra -- 2014-01-21
      4 
      5 W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay"
      6 FONTH=16 # Size of one terminal row
      7 FONTW=9 # Size of one terminal column
      8 
      9 X=$1
     10 Y=$2
     11 COLUMNS=$3
     12 LINES=$4
     13 FILENAME=$5
     14 
     15 read width height <<< `echo "5;$FILENAME" | $W3MIMGDISPLAY`
     16 if [ -z "$width" -o -z "$height" ]; then
     17     echo 'Error: Failed to obtain image size.'
     18     exit 1
     19 fi
     20 
     21 x=$((FONTW * X))
     22 y=$((FONTH * Y))
     23 
     24 max_width=$((FONTW * COLUMNS))
     25 max_height=$((FONTH * LINES))
     26 
     27 if [ "$width" -gt "$max_width" ]; then
     28     height=$((height * max_width / width))
     29     width=$max_width
     30 fi
     31 if [ "$height" -gt "$max_height" ]; then
     32     width=$((width * max_height / height))
     33     height=$max_height
     34 fi
     35 
     36 w3m_command="0;1;$x;$y;$width;$height;;;;;$FILENAME\n4;\n3;"
     37 
     38 echo -e "$w3m_command" | $W3MIMGDISPLAY