-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitscan
executable file
·145 lines (123 loc) · 2.92 KB
/
splitscan
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
#!/bin/bash
#
# Licensing:
#
# Copyright © Laurence Lumi 2018
# Licensed GNU General Public License v3
# which can be found here https://www.gnu.org/licenses/gpl-3.0.en.html
#
progname=`basename $0`
usage()
{
echo >&2 ""
echo >&2 "$progname:" "$@"
cat << MESSAGE1
USAGE: $progname [-d] [-dd] [-q] [-h] [-t] [-z] infile [outfile_prefix]
USAGE: $progname [-d] [-dd] [-quarter] [-half] [-three] infile [outfile_prefix]
USAGE: $progname [-help]
OPTIONS:
-z zip zip compress the output (the default is not compress the output)
MESSAGE1
exit 1
}
help()
{
echo >&2 ""
echo >&2 "$progname:" "$@"
cat >&2 << MESSAGE2
NAME: $progname
PURPOSE: TODO
Arguments:
MESSAGE2
exit 1
}
function DEBUG()
{
[ ! "$debug" -eq 0 ] && $@
}
tmpdir="./"
debug=0
tmpprefix=$tmpdir"_sp_"
comment="Processed with splitscan"
DEBUG echo -set comment "$comment"
prof_dir=$HOME/.scantools
zip="+compress"
mkdir -p "$prof_dir"
while [ $# -gt 0 ]
do
# get parameters
case "$1" in
-help) # help information note no -h
echo ""
help
;;
-d) debug=1
;;
-dd) debug=2
;;
-q|-quarter)
split="quarter"
;;
-h|-half)
split="half"
;;
-t|-three)
split="three_quarter"
;;
-z)
zip="-compress zip"
;;
-) # STDIN and end of arguments
break
;;
-*) # any other - argument
echo "--- UNKNOWN OPTION ---" $1
usage
;;
*) # end of arguments
break
;;
esac
shift # next option
done
infile=$1
outprefix=$2
if [ -z $infile ]; then
echo "must provide a filename"
usage
fi
if [ ! -f "$infile" -o ! -r "$infile" ]; then
echo "Cannot open: $infile"
exit 1
fi
if [ -z $outprefix ]; then
outprefix=${infile%".tif"}_
else
outprefix=${outprefix%".tif"}_
fi
DEBUG echo outprefix: $outprefix
DEBUG set -x
X=`identify -format "%w" $infile`
if [ "$split" = "quarter" ]; then
DEBUG echo split = $split
X1=`convert xc: -format "%[fx: $X *.25]" info:`
X2=`convert xc: -format "%[fx: $X *.75]" info:`
elif [ "$split" = "half" ]; then
DEBUG echo split = $split
X1=`convert xc: -format "%[fx: $X *.5]" info:`
X2=$X1
elif [ "$split" = "three_quarter" ]; then
DEBUG echo split = $split
X1=`convert xc: -format "%[fx: $X *.75]" info:`
X2=`convert xc: -format "%[fx: $X *.25]" info:`
else
echo "nothing to do, you must split by quarter, half or three (quarters)"
exit 1
fi
Y=`identify -format "%h" $infile`
DEBUG echo X1, X2 and Y: $X1, $X2 and $Y
echo spliting file:"$outprefix"A.tif
convert $infile +repage -crop "$X1"x"$Y"+0+0 +repage $zip "$outprefix"A.tif
echo spliting file:"$outprefix"B.tif
convert $infile +repage -crop "$X2"x"$Y"+"$X1"+0 +repage $zip "$outprefix"B.tif
exit 0