capture 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/sh
  2. # Set settings, make a camera take photos.
  3. # TODO
  4. # - In filenames, save setting values instead of option numbers.
  5. # - Take shots with incrimenting/decrimenting values over a range.
  6. # - Timed shots.
  7. cimg="capt0000.jpg" # name of file from camera
  8. usage="Usage: $0 i # a # s # w #
  9. Any or all paramaters can be excluded, you will be prompted \
  10. with a list of options. All values are numerical options \
  11. offered by the camera, not the desired value."
  12. while [ $# -gt 0 ]
  13. do
  14. case "$1" in
  15. i*) i="$2"; shift ;; # iso
  16. a*) a="$2"; shift ;; # aperture
  17. s*) s="$2"; shift ;; # shutter speed
  18. w*) w="$2"; shift ;; # white balance
  19. *) echo "$usage"; exit ;;
  20. esac
  21. shift
  22. done
  23. precap() {
  24. if [ -z "$i" ]; then # check if option is set
  25. gphoto2 --get-config "iso" # get options from camera
  26. printf '? ' # prompt for input
  27. read i
  28. fi
  29. if [ -z "$a" ]; then
  30. gphoto2 --get-config "aperture"
  31. printf '? '
  32. read a
  33. fi
  34. if [ -z "$s" ]; then
  35. gphoto2 --get-config "shutterspeed"
  36. printf '? '
  37. read s
  38. fi
  39. if [ -z "$w" ]; then
  40. gphoto2 --get-config "whitebalance"
  41. printf '? '
  42. read w
  43. fi
  44. }
  45. cap() {
  46. # display settings and pause
  47. echo "
  48. ISO: $i
  49. Shutter: $s
  50. Aperture: $a
  51. Press [ENTER] to take photo:"
  52. read opt
  53. # note time and settings used
  54. oimg="$(date +%y%m%d-%H%M%S)-i${i}-a${a}-s${s}.jpg"
  55. # set options
  56. gphoto2 --set-config "iso=$i"
  57. gphoto2 --set-config "whitebalance=$w"
  58. gphoto2 --set-config "aperture=$a"
  59. gphoto2 --set-config "shutterspeed=$s"
  60. # turn the screen off
  61. xrandr --output LVDS --off
  62. sleep 1
  63. # capture the image
  64. echo "Taking photo..."
  65. gphoto2 --capture-image-and-download
  66. }
  67. postcap() {
  68. # turn the screen back on
  69. xrandr --output LVDS --auto --below HDMI-0
  70. # rename the image
  71. mv "$cimg" "$oimg"
  72. # display the image
  73. feh -.B black "$oimg"
  74. # prompt and delete the image
  75. printf 'Keep image? '
  76. read opt
  77. case "$opt" in
  78. n) rm -f "$oimg" ;;
  79. y) ;;
  80. esac
  81. }
  82. precap # gather information before capturing image
  83. cap # set options and capture image
  84. postcap # rename, display and give option to discard