-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotobooth-print.sh
executable file
·212 lines (177 loc) · 3.67 KB
/
photobooth-print.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
#variables
set -e
tmp=/var/www/photobooth/photos/tmp
backup_dir=/var/www/photobooth/photos/backup
final=/var/www/photobooth/photos/final
upload_dir=/home/jnwark/Dropbox/Public/photobooth
display_file=/var/www/photobooth/photos/final/current.png
overlay=/home/jnwark/Dropbox/Public/photobooth/overlay.png
#nashville, toaster, gotham, lomo, kelvin
#filter=gotham
countdown=false
print=false
upload=true
#layouts
# 2x2 = +2+2
# 4x1 = +4+1
layout="1x"
if [ "$1" = "single" ]
then
frame=false
else
frame=true
fi
red='\e[0;31m'
NC='\e[0m' # No Color
function echo_info
{
echo -e ${red}$1${NC}
}
function backup_images
{
for f in $tmp/*
do
cp_increment $f $backup_dir
done
}
function print_images
{
lp $tmp/
for f in $tmp/*
do
lp $f
done
}
function cp_increment
{
#source=dirA/file.ext
#dest_dir=dirB
source_file=$1
dest_dir=$2
file=$(basename capt0000.jpg)
basename=${file%.*}
ext=${file##*.}
if [[ ! -e "$dest_dir/$basename.$ext" ]]; then
# file does not exist in the destination directory
cp "$source_file" "$dest_dir"
else
num=2
while [[ -e "$dest_dir/$basename$num.$ext" ]]; do
(( num++ ))
done
cp "$source_file" "$dest_dir/$basename$num.$ext"
fi
}
function cp_upload
{
#source=dirA/file.ext
#dest_dir=dirB
source_file=$1
dest_dir=$2
echo "1 = $1"
echo "2 = $2"
file=$(basename upload.png)
basename=${file%.*}
ext=${file##*.}
#echo "$dest_dir/$basename.$ext"
num=2
while [[ -e "$dest_dir/$basename$num.$ext" ]]; do
# echo "num = $num"
(( num++ ))
done
cp "$source_file" "$dest_dir/$basename$num.$ext"
}
echo_info "Start"
echo_info $1
#delete tmp files
echo_info "delete tmp files"
mkdir -p $tmp
cd $tmp
rm -f *.jpg *.png
#check camera
#capture 4 photos
if [ $frame = true ]
then
echo_info "capture 4 photos"
cd $tmp
# sleep 5
gphoto2 --capture-image-and-download --frames 4 --interval 2
fi
#capture single photo
if [ $frame = false ]
then
echo_info "capture single photo"
cd $tmp
#sleep 5
gphoto2 --capture-image-and-download
fi
# print to label printer
print_images
#back up raw images
echo_info "back up raw images"
backup_images
#combine
if [ $frame = true ]
then
echo_info "combine"
cd $tmp
last=$(ls -t *.jpg | head -1)
mogrify -resize 600x400 -bordercolor black -border 2 *.jpg
montage -tile ${layout} -geometry 600x400\>+2+2 *.jpg $last
#montage -geometry 300x200\>${layout} *.jpg $last
if [ $overlay ]
then
composite -gravity center -geometry +0+100 $last $overlay ${last}.png
fi
fi
if [ $frame = false ]
then
echo_info "resize"
cd $tmp
last=$(ls -t *.jpg | head -1)
convert $last -resize 600x400 $last
fi
#copy final file to final folder
echo_info "copy final file to final folder"
cd $tmp
last=$(ls -t *.png | head -1)
cp $last $final
#filter photo
echo_info "filter photo"
if [ "$filter" = "nashville" ]
then cd $final
convert $last -contrast -modulate 100,150,100 -auto-gamma $last
fi
if [ "$filter" = "toaster" ]
then cd $final
convert $last -modulate 150,80,100 -gamma 1.2 -contrast -contrast $last
fi
if [ "$filter" = "gotham" ]
then cd $final
convert $last -modulate 120,10,100 -fill '#222b6d' -colorize 10 -contrast -contrast $last
fi
if [ "$filter" = "lomo" ]
then cd $final
convert $last -channel R -level 33% -channel G -level 33% $last
fi
if [ "$filter" = "kelvin" ]
then cd $final
convert $last -auto-gamma -modulate 120,50,100 -fill 'rgba(255,153,0,0.5)' -draw 'rectangle 0,0 2304,1536' -compose multiply $last
fi
#print
echo_info "print"
#upload
if [ $upload = true ]
then
echo_info "uploading to dropbox"
#cp $last $upload_dir
cp_upload $last $upload_dir
fi
#store for local display
echo_info "copy for display"
cp $last $display_file
#delete tmp files
echo_info "delete tmp files"
cd $tmp
rm -f *.jpg *.png