Guest User

Untitled

a guest
Oct 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # z3bra -- 2014-01-21
  4.  
  5. if [[ $# != 2 ]]; then
  6. echo "Insufficient arguments."
  7. exit 1
  8. fi
  9.  
  10. W3MIMGDISPLAY="/usr/libexec/w3m/w3mimgdisplay"
  11. FILENAME="${2}"
  12. FONTH=14 # Size of one terminal row
  13. FONTW=8 # Size of one terminal column
  14. COLUMNS=`tput cols`
  15. LINES=`tput lines`
  16.  
  17. read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`
  18.  
  19. max_width=$(($FONTW * $COLUMNS))
  20. max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt
  21.  
  22. if test $width -gt $max_width; then
  23. height=$(($height * $max_width / $width))
  24. width=$max_width
  25. fi
  26. if test $height -gt $max_height; then
  27. width=$(($width * $max_height / $height))
  28. height=$max_height
  29. fi
  30.  
  31. while getopts ":c:d" COMMAND;
  32. do
  33. case ${COMMAND} in
  34. c) w3m_command="6;0;0;$width;$height;\n4;\n3;"
  35. ;; # Clear image
  36. d) w3m_command="0;1;0;0;$width;$height;;;;;$FILENAME\n4;\n3;"
  37. ;; # Draw image
  38. esac
  39. done
  40.  
  41. tput cup $(($height/$FONTH)) 0
  42. echo -e $w3m_command|$W3MIMGDISPLAY
Add Comment
Please, Sign In to add comment