Skip to content

Instantly share code, notes, and snippets.

@jerico
Created December 21, 2011 17:01
Show Gist options
  • Save jerico/1506779 to your computer and use it in GitHub Desktop.
Save jerico/1506779 to your computer and use it in GitHub Desktop.
Very rough photobooth script using gPhoto2, ImageMagick, and CUPS.
#! /usr/bin/env bash
# Extremely rough photobooth bash script
# It depends on the following:
# - gPhoto2: for camera control through usb
# - ImageMagick: photo-manipulation suite
# - CUPS: printer driver with command-line printing utilities
# - beep: for the countdown sound
save_dir=./processed
prefix=Xmas2011
overlays=(./overlays/*.png)
current_overlay=`cat ./overlays/current`
print=true
beeper=true
# Start infinite loop.
if [ "$1" = start ]; then
while true; do
read -sn 1 -p "Press any key to start shooting. Ctrl-C to quit."
# initialize shot count
echo "0" > ./count
gphoto2 -F 3 -I 3 --capture-image-and-download --force-overwrite --hook-script $0
done
fi
# Checks if save directory exists, if not create it
! [ -d $save_dir ] && mkdir "$save_dir"
function process() {
# Get the last number of the last shot
all_files=($save_dir/*.jpg)
last_file_num=`echo ${all_files[-1]:(-7):3} | sed 's/^[0]*//'`
if [ -e ${save_dir}/${prefix}_001.jpg ]; then
last_file_num=`printf "%03d" $((last_file_num+1))`
else
last_file_num=`printf "%03d" 1`
fi
# Process shots
mkdir .tmp
convert $4 -sigmoidal-contrast 3,30% -resize 1077x721 -rotate -7 .tmp/1.png
convert $3 -sigmoidal-contrast 3,30% -resize 300x201 .tmp/2.png
convert -sigmoidal-contrast 3,30% -resize 300x201 -rotate -12 -background transparent $2 .tmp/3.png
convert -size 1800x1200 xc:white \
.tmp/1.png -geometry +129+232 -composite \
.tmp/2.png -geometry +156+117 -composite \
.tmp/3.png -geometry +492+60 -composite \
$1 -composite ${save_dir}/${prefix}_${last_file_num}.jpg
next_overlay
rm -rf .tmp
if $print ; then print ${save_dir}/${prefix}_${last_file_num}.jpg ; fi
}
function countdown() {
beep -f 1000 -r 6 -d 600 -n -f 1000 -r 5 -d 0
}
function print() {
lp -o media=4x6.bl,prophoto2 -o scaling=100 -o brightness=103 $1
}
function next_overlay() {
if [ $current_overlay -lt 2 ]; then
next_overlay=$((current_overlay+1))
else
next_overlay=0
fi
echo $next_overlay > ./overlays/current
}
# if arguments is equal to 4, process images
[ $# = 4 ] && process "$1" "$2" "$3" "$4"
# if arg is print
[ "$1" = print ] && print $2
# gphoto hook script
if [[ $ACTION ]]; then
if [ $ACTION = start ]; then
if $beeper ; then countdown ; fi
fi
if [ $ACTION = stop ]; then
process ${overlays[$current_overlay]} capt0000.jpg capt0001.jpg capt0002.jpg
rm ./count
fi
if [ $ACTION = download ]; then
# prevents countdown after the last shot.
COUNT=$(cat ./count)
if [ $COUNT -lt 2 ]; then
COUNT=$[$COUNT + 1]
if $beeper ; then countdown ; fi
echo $COUNT > ./count
fi
fi
fi
@RALi18
Copy link

RALi18 commented Aug 9, 2018

. . . on the raspberri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment