img_script.sh 790 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. #
  3. #source http://blog.z3bra.org/2014/01/images-in-terminal.html
  4. # z3bra -- 2014-01-21
  5. test -z "$1" && exit
  6. W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay"
  7. FILENAME=$1
  8. FONTH=14 # Size of one terminal row
  9. FONTW=8 # Size of one terminal column
  10. COLUMNS=`tput cols`
  11. LINES=`tput lines`
  12. read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`
  13. max_width=$(($FONTW * $COLUMNS))
  14. max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt
  15. if test $width -gt $max_width; then
  16. height=$(($height * $max_width / $width))
  17. width=$max_width
  18. fi
  19. if test $height -gt $max_height; then
  20. width=$(($width * $max_height / $height))
  21. height=$max_height
  22. fi
  23. w3m_command="0;1;0;0;$width;$height;;;;;$FILENAME\n4;\n3;"
  24. tput cup $(($height/$FONTH)) 0
  25. echo -e $w3m_command|$W3MIMGDISPLAY