You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.7KB

  1. #!/bin/bash
  2. INDIR="$HOME/wp/curr"
  3. OUTDIR="$HOME/wp/curr"
  4. mkdir -p "$OUTDIR"
  5. sedstr="\([0-9][0-9]*\)x\([0-9][0-9]*\)+\([0-9][0-9]*\)+\([0-9][0-9]*\)"
  6. function getinfo() {
  7. xrandr -q | grep "^$1" | grep -o "[0-9][0-9]*x[0-9][0-9]*+[0-9][0-9]*+[0-9][0-9]*"
  8. }
  9. function getres() {
  10. getinfo "$1" | sed "s:$sedstr:\1x\2:"
  11. }
  12. function getoff() {
  13. getinfo "$1" | sed "s:$sedstr:+\3+\4:"
  14. }
  15. function getwidth() {
  16. getinfo "$1" | sed "s:$sedstr:\1:"
  17. }
  18. function getheight() {
  19. getinfo "$1" | sed "s:$sedstr:\2:"
  20. }
  21. function getleft() {
  22. getinfo "$1" | sed "s:$sedstr:\3:"
  23. }
  24. function gettop() {
  25. getinfo "$1" | sed "s:$sedstr:\4:"
  26. }
  27. function screenres() {
  28. xrandr -q | grep "^Screen 0" | sed 's:^.*current \([0-9][0-9]*\) x \([0-9][0-9]*\).*$:\1x\2:'
  29. }
  30. function run() {
  31. echo "$@"
  32. "$@"
  33. }
  34. function main() {
  35. local joinargs=()
  36. while [ -n "$1" ] && [ "$1" != "--" ]; do
  37. local res="$(getres "$1")"
  38. run convert "$INDIR/motif.png" -resize "$res^" -gravity center -extent "$res" "$OUTDIR/$1.png"
  39. joinargs+=("$OUTDIR/$1.png" -geometry "$(getoff "$1")" -composite)
  40. shift
  41. done
  42. shift
  43. if [ -n "$1" ]; then
  44. local splitargs=()
  45. local off=0
  46. local maxh=0
  47. while [ -n "$1" ]; do
  48. splitargs+=(\( -clone 0 -gravity West -extent "$(getres "$1")+$off+0" -write "$OUTDIR/$1.png" +delete \))
  49. joinargs+=("$OUTDIR/$1.png" -geometry "$(getoff "$1")" -composite)
  50. off=$((off + $(getwidth "$1")))
  51. if [ "$maxh" -lt "$(getheight "$1")" ]; then
  52. maxh="$(getheight "$1")"
  53. fi
  54. shift
  55. done
  56. run convert -respect-parenthesis "$INDIR/panorama.png" -resize "${off}x${maxh}^" "${splitargs[@]}" "jpg:/dev/null"
  57. fi
  58. run convert -respect-parenthesis -size "$(screenres)" 'xc:#000000' "${joinargs[@]}" "$OUTDIR/all.png"
  59. }
  60. main "$@"