-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbinn
executable file
·43 lines (33 loc) · 925 Bytes
/
binn
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
#!/bin/bash -e
if [ $# -lt 3 ]; then
cat >&2 <<EOF
$(basename $0) <input> <output> <factor>
Take a photo and shrink it by the binning_factor to improve
signal to noise ratio. Binning factor must be a whole number,
and input image may be cropped slightly to ensure its size is a
whole number of 'bins'.
Original Script by Walter Dnes <waltdnes@waltdnes.org>
EOF
exit 1
fi
source_file=${1}
output_file=${2}
bin_size=${3}
set -$- `identify -format '%w %h' "${1}"`
x=$1 y=$2
newx=$((${x} / ${bin_size}))
checkx=$((${newx} * ${bin_size}))
if [[ ${checkx} -ne ${x} ]]; then
crop_flag="YES"
fi
newy=$((${y} / ${bin_size}))
checky=$((${newy} * ${bin_size}))
if [[ ${checky} -ne ${y} ]]; then
crop_flag="YES"
fi
if [ "$crop_flag" ]; then
crop_args="-crop ${checkx}x${checky}+0+0 +repage"
fi
convert "${source_file}" $crop_args \
-filter box -resize "${newx}x${newy}" \
"${output_file}"