Advertisement
Twilypastes

takeshot w/ margin

Nov 23rd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Profile:     http://www.ugra.ch/iso-color-profiles.phtml
  4. #
  5. # Author:      Twily                               2014
  6. # Description: Capture a window with a margin around it
  7. # Requires:    imagemagic, xwininfo, ISOcoated_v2_300_eci.icc
  8. # Useage:      $ sh ./takeshot filename.png
  9. #
  10.  
  11. M=24    # Margin
  12. D=24    # Decoration
  13.  
  14. if [ -z $1 ]; then set -- "window.png"; fi
  15.  
  16. echo -e "\ntakeshot: Please select the window you would like to\n" \
  17.             "         capture by clicking the mouse in that window.\n"
  18.  
  19. unset X Y W H
  20. eval $(xwininfo |
  21.     sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/X=\1/p" \
  22.            -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/Y=\1/p" \
  23.            -e "s/^ \+Width: \+\([0-9]\+\).*/W=\1/p" \
  24.            -e "s/^ \+Height: \+\([0-9]\+\).*/H=\1/p" )
  25.  
  26. W=`expr $W + $M \* 2`
  27. H=`expr $H + $M \* 2 + $D`
  28. X=`expr $X - $M`
  29. Y=`expr $Y - $M - $D`
  30.  
  31. import -window root -crop $W'x'$H+$X+$Y "takeshot.tmp.png" || exit 1
  32. convert "takeshot.tmp.png" -profile ~/.icc/ISOcoated_v2_300_eci.icc "$1" &>/dev/null || exit 1
  33.  
  34. echo -e "Window captured and saved to \"\e[1;32m~/$1\e[0m\"."
  35. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement