rev |
line source |
pascal@18237
|
1 #!/bin/sh
|
pascal@18237
|
2 #
|
pascal@18237
|
3 # Scanner CGI interface - Scan documents via a browser
|
pascal@18237
|
4 #
|
pascal@18237
|
5 # (C) 2015 SliTaz GNU/Linux - BSD License
|
pascal@18237
|
6 #
|
pascal@18237
|
7
|
pascal@18237
|
8 # Common functions from libtazpanel
|
pascal@18237
|
9 . lib/libtazpanel
|
pascal@18237
|
10 get_config
|
pascal@18237
|
11
|
pascal@18237
|
12 #------
|
pascal@18237
|
13 # menu
|
pascal@18237
|
14 #------
|
pascal@18237
|
15
|
pascal@18237
|
16 case "$1" in
|
pascal@18237
|
17 menu)
|
pascal@18237
|
18 TEXTDOMAIN_original=$TEXTDOMAIN
|
pascal@18237
|
19 export TEXTDOMAIN='sane'
|
pascal@18237
|
20
|
pascal@18237
|
21 cat <<EOT
|
pascal@18237
|
22 <li><a data-icon="text" href="sane.cgi"$(groups | grep -q scanner ||
|
pascal@18237
|
23 echo ' data-root')>$(_ 'Scanner')</a></li>
|
pascal@18237
|
24 EOT
|
pascal@18237
|
25 export TEXTDOMAIN=$TEXTDOMAIN_original
|
pascal@18237
|
26 exit
|
pascal@18237
|
27 esac
|
pascal@18237
|
28
|
pascal@18237
|
29 TITLE="$(_ 'TazPanel - Hardware') - $(_ 'Scanner')"
|
pascal@18237
|
30
|
pascal@18237
|
31 inrange() {
|
pascal@18237
|
32 local n=$1
|
pascal@18237
|
33 [ $1 -lt $2 ] && n=$2
|
pascal@18237
|
34 [ $1 -gt $3 ] && n=$3
|
pascal@18237
|
35 echo $n
|
pascal@18237
|
36 }
|
pascal@18237
|
37
|
pascal@18237
|
38 getgeometry() {
|
pascal@18237
|
39 CMD=""
|
pascal@18242
|
40 ARGS=""
|
pascal@18242
|
41 for i in x y l t ; do
|
pascal@18237
|
42 j=$(inrange $(xPOST geometry_$i) $(xPOST ${i}_min) $(xPOST ${i}_max))
|
pascal@18237
|
43 eval "geometry_$i=$j"
|
pascal@18237
|
44 CMD="$CMD -$i $j"
|
pascal@18242
|
45 ARGS="$ARGS $j"
|
pascal@18237
|
46 done
|
pascal@21768
|
47 for i in $(POST) ; do
|
pascal@21768
|
48 case $i in
|
pascal@21768
|
49 preview|format|resolution|res_min|res_max|l_min|l_max);;
|
pascal@21768
|
50 geometry_l|t_min|t_max|geometry_t|x_min|x_max|geometry_x);;
|
pascal@21768
|
51 y_min|y_max|geometry_y|tmpreview|device|params);;
|
pascal@21768
|
52 *) v="$(xPOST $i)"; i="--${i//_/-}"
|
pascal@21768
|
53 case "$v" in
|
pascal@21768
|
54 '') ;;
|
pascal@21768
|
55 yes|no) CMD="$CMD $i=$v" ;;
|
pascal@21768
|
56 *) CMD="$CMD $i '$v'" ;;
|
pascal@21768
|
57 esac
|
pascal@21768
|
58 esac
|
pascal@18237
|
59 done
|
pascal@18237
|
60 resolution=${1:-0}
|
pascal@18237
|
61 if [ $resolution -eq 0 ]; then
|
pascal@18237
|
62 resolution=$(xPOST res_min)
|
pascal@18237
|
63 width=$(GET width)
|
pascal@18237
|
64 [ ${geometry_x:-0} -le 0 ] && geometry_x=$(xPOST x_max)
|
pascal@18237
|
65 while [ $((${resolution:=150} * ${geometry_x%.*})) -lt ${width:-8192} ]; do
|
pascal@18237
|
66 resolution=$(($resolution * 2))
|
pascal@18237
|
67 done
|
pascal@18237
|
68 fi
|
pascal@18242
|
69 case "$(xPOST mode)" in
|
pascal@18242
|
70 *lack*|*ineart*) mode="-monochrome" ;;
|
pascal@18242
|
71 *ray*) mode="-colorspace gray" ;;
|
pascal@18242
|
72 *) mode="" ;;
|
pascal@18242
|
73 esac
|
pascal@18237
|
74 [ -d tmp ] || ln -s /tmp tmp
|
pascal@18237
|
75 case "$device" in
|
pascal@20172
|
76 fake*) f=$(ls fake-sane/*.png | sed q)
|
pascal@20172
|
77 [ -s "$f" ] || f=/usr/share/images/slitaz-banner.png
|
pascal@18242
|
78 c="$(echo $ARGS $(identify $f | sed \
|
pascal@18242
|
79 's/.* \([0-9]*\)x.*/\1/') $(GET width) $(POST x_max) | awk '
|
pascal@18242
|
80 function a(x) { return int(($x * $5)/ $7); }
|
pascal@18242
|
81 { printf "%dx%d+%d+%d -resize %dx%d",a(1),a(2),a(3),a(4),$6,int(($2*$6)/$1)}
|
pascal@18242
|
82 ')"
|
pascal@18252
|
83 suf="png"; [ "$1" ] && suf="pnm"
|
pascal@18242
|
84 cat <<EOT
|
pascal@21768
|
85 if convert -crop $c $mode $f /tmp/sane$$.$suf ; then
|
pascal@18252
|
86 cat /tmp/sane$$.$suf
|
pascal@18252
|
87 rm -f /tmp/sane$$.$suf
|
pascal@18242
|
88 else
|
pascal@18242
|
89 cat $f
|
pascal@21768
|
90 fi 2> /dev/null
|
pascal@18242
|
91 EOT
|
pascal@18242
|
92 ;;
|
pascal@18242
|
93 *) echo -n "scanimage -d '$(echo $device | sed 's/,.*//')' --resolution '$(inrange $resolution $(xPOST res_min) $(xPOST res_max))dpi'$CMD"
|
pascal@18242
|
94 if [ -z "$1" -a "$(which convert)" ]; then
|
pascal@18242
|
95 echo -n "> /tmp/sane$$.pnm ; convert -resize "
|
pascal@21769
|
96 echo $ARGS 1024 | awk '{ printf "%dx%d",$5,int(($2*$5)/$1)}'
|
pascal@18242
|
97 echo -n " /tmp/sane$$.pnm /tmp/sane$$.png ;"
|
pascal@18242
|
98 echo -n "cat /tmp/sane$$.png ; rm -f /tmp/sane$$.pn?"
|
pascal@18242
|
99 fi
|
pascal@18237
|
100 esac
|
pascal@18237
|
101 }
|
pascal@18237
|
102
|
pascal@18237
|
103 imgformat() {
|
pascal@18237
|
104 tmp=$(mktemp -u -t tazsane.XXXXXX)
|
pascal@21771
|
105 pnm2png=convert; pnm2png_cmd="> $tmp.pnm; convert $tmp.pnm png:-"
|
pascal@21771
|
106 [ "$(which pnm2png)" ] && pnm2png=pnm2png && pnm2png_cmd="|pnm2png"
|
pascal@18237
|
107 while read key name type exe pkg cmd ; do
|
pascal@18237
|
108 case "$key" in
|
pascal@18237
|
109 \#*) continue
|
pascal@18237
|
110 esac
|
pascal@18237
|
111 case "$1" in
|
pascal@18237
|
112 list)
|
pascal@18237
|
113 echo -n "<option value=\"$key\""
|
pascal@21769
|
114 disabled=""
|
pascal@21769
|
115 for i in ${exe//|/ }; do
|
pascal@21769
|
116 [ "$(which $i 2> /dev/null)" ] ||
|
pascal@21769
|
117 disabled=" disabled title=\"$i not found: install package $pkg\""
|
pascal@21769
|
118 done
|
pascal@21769
|
119 echo -n "$disabled"
|
pascal@18237
|
120 [ "$key" == "pnm" ] &&
|
pascal@18237
|
121 echo -n " title=\"not supported by most browsers\""
|
pascal@18237
|
122 echo ">$key" ;;
|
pascal@18237
|
123 *)
|
pascal@18237
|
124 case "$key" in
|
pascal@18237
|
125 $(xPOST format)|'*')
|
pascal@18237
|
126 case "$HTTP_USER_AGENT" in
|
pascal@18237
|
127
|
pascal@18237
|
128 # Tazweb has no download support
|
pascal@18237
|
129 TazWe*) rm -f /tmp/$name
|
pascal@18237
|
130 eval "$(getgeometry $(xPOST resolution)) $cmd >/tmp/$name" 2> $tmp.err
|
pascal@18237
|
131 if [ -s /tmp/$name ]; then
|
pascal@18237
|
132 info="Stored in /tmp/$name ($(stat -c %s /tmp/$name) bytes)."
|
pascal@18237
|
133 else
|
pascal@18237
|
134 error="$(sed 's|$|<br />|' $tmp.err)"
|
pascal@18237
|
135 [ "$error" ] || error="I/O error"
|
pascal@18237
|
136 fi
|
pascal@18237
|
137 rm -f $tmp.* ;;
|
pascal@18237
|
138
|
pascal@18237
|
139 # Others should work
|
pascal@18237
|
140 *) header "Content-Type: $type" \
|
pascal@18237
|
141 "Content-Disposition: attachment; filename=$name" \
|
pascal@18237
|
142
|
pascal@18237
|
143 eval "$(getgeometry $(xPOST resolution)) $cmd"
|
pascal@18237
|
144 rm -f $tmp.*
|
pascal@18237
|
145 exit ;;
|
pascal@18237
|
146 esac ;;
|
pascal@18237
|
147 esac ;;
|
pascal@18237
|
148 esac
|
pascal@18237
|
149 done <<EOT
|
pascal@21771
|
150 png tazsane.png image/png $pnm2png imagemagick $pnm2png_cmd
|
pascal@18237
|
151 jpeg tazsane.jpg image/jpeg convert imagemagick > $tmp.pnm; convert $tmp.pnm jpg:-
|
pascal@18237
|
152 jpeg2000 tazsane.jp2 image/jpeg2000-image convert imagemagick > $tmp.pnm; convert $tmp.pnm jp2:-
|
pascal@18237
|
153 tiff tazsane.tiff image/tiff convert imagemagick > $tmp.pnm; convert $tmp.pnm tiff:-
|
pascal@18237
|
154 ps tazsane.ps application/postscript convert imagemagick > $tmp.pnm; convert -page A4+0+0 $tmp.pnm ps:-
|
pascal@18237
|
155 pdf tazsane.pdf image/pdf convert imagemagick > $tmp.pnm; convert $tmp.pnm pdf:-
|
pascal@18237
|
156 ocr1 tazsane-OCR1.txt text/plain gocr gocr | gocr -
|
pascal@18237
|
157 ocr2 tazsane-OCR2.txt text/plain tesseract tesseract-ocr | tesseract stdin stdout
|
pascal@18237
|
158 pnm tazsane.pnm image/pnm true slitaz
|
pascal@18237
|
159 EOT
|
pascal@18237
|
160 }
|
pascal@18237
|
161
|
pascal@18237
|
162 xPOST() {
|
pascal@18237
|
163 [ "$preview" == "reset" ] || POST $@
|
pascal@18237
|
164 }
|
pascal@18237
|
165
|
pascal@18237
|
166 tmpreview="$(POST tmpreview)"
|
pascal@18237
|
167 find tmp/ -name 'tazsane*' -mmin +60 -prune -exec rm -f {} \;
|
pascal@18237
|
168
|
pascal@18237
|
169 device="$(POST device)"
|
pascal@18237
|
170 preview="$(POST preview)"
|
pascal@18237
|
171 info=""
|
pascal@18237
|
172 error=""
|
pascal@18237
|
173
|
pascal@18237
|
174 case " $(POST) " in
|
pascal@18237
|
175 *\ reset\ *)
|
pascal@18237
|
176 unset device tmpreview
|
pascal@18237
|
177 preview="reset" ;;
|
pascal@18237
|
178 *\ preview\ *)
|
pascal@18237
|
179 [ "$tmpreview" ] || tmpreview=$(mktemp -u -t tazsane.XXXXXX).png
|
pascal@18237
|
180 tmp=$(mktemp -u -t tazsane.XXXXXX)
|
pascal@18237
|
181 eval "$(getgeometry)" > $tmp.pnm 2> $tmp.err
|
pascal@18237
|
182 if [ -s "$tmp.pnm" ]; then
|
pascal@18237
|
183 convert $tmp.pnm $tmpreview > /dev/null 2>&1 ||
|
pascal@21768
|
184 pnm2png < $tmp.pnm > $tmpreview ||
|
pascal@18237
|
185 cp $tmp.pnm $tmpreview
|
pascal@18237
|
186 else
|
pascal@18237
|
187 error="$(sed 's|$|<br />|' $tmp.err)"
|
pascal@18237
|
188 rm -f $tmpreview
|
pascal@18237
|
189 fi
|
pascal@18237
|
190 rm -f $tmp.pnm $tmp.err ;;
|
pascal@18237
|
191 *\ scan\ *)
|
pascal@18237
|
192 imgformat download ;;
|
pascal@18237
|
193 esac
|
pascal@18237
|
194
|
pascal@18237
|
195 header
|
pascal@18237
|
196 xhtml_header
|
pascal@18237
|
197 [ -n "$error" ] && msg warn "$error"
|
pascal@18237
|
198 [ -n "$info" ] && msg tip "$info"
|
pascal@18237
|
199 if [ -z "$device" ]; then
|
pascal@21768
|
200 suggested=""
|
pascal@21768
|
201 while read exe pkg msg; do
|
pascal@21768
|
202 [ "$(which $exe 2> /dev/null)" ] && continue
|
pascal@21768
|
203 suggested="$suggested
|
pascal@21768
|
204 <li><a href=\"/user/pkgs.cgi?info=$pkg\">$pkg</a> $msg</li>"
|
pascal@21768
|
205 done <<EOT
|
pascal@21768
|
206 convert imagemagick $(_ "to preview images and support more image formats (recommended)")
|
pascal@21768
|
207 gocr gocr $(_ "a basic optical character recognition")
|
pascal@21768
|
208 tesseract tesseract-ocr $(_ "a better optical character recognition")
|
pascal@21768
|
209 EOT
|
pascal@21768
|
210 [ "$suggested" ] &&
|
pascal@21768
|
211 msg tip "$(_ "You may need to install:") <ol>$suggested</ol>"
|
pascal@20172
|
212 all="$(scanimage -f '%d,%v %m|'|\
|
pascal@20172
|
213 cat - sane-fake.log fake-sane/sane-fake.log |sed 's/|/\n/g')"
|
pascal@18237
|
214 case "$(echo "$all" | wc -l)" in
|
pascal@18237
|
215 1) if [ -z "$all" ]; then
|
pascal@18242
|
216 msg warn "$(_ "No scanner found")"
|
pascal@18242
|
217 msg tip "$(_ "You can test this GUI with ")\
|
pascal@18242
|
218 <a href=\"/user/pkgs.cgi?info=fake-sane\">fake-sane</a>"
|
pascal@18237
|
219 xhtml_footer
|
pascal@18237
|
220 exit 0
|
pascal@18237
|
221 fi
|
pascal@21768
|
222 if [ "$suggested" ]; then
|
pascal@21768
|
223 cat <<EOT
|
pascal@21768
|
224 <section>
|
pascal@21768
|
225 <header>
|
pascal@21768
|
226 <form name="scanner" method="post">
|
pascal@21768
|
227 <input type="hidden" name="device" value="$all">
|
pascal@21768
|
228 Scanner ${all#*,}
|
pascal@21768
|
229 <button data-icon="start">Continue</button>
|
pascal@21768
|
230 </form>
|
pascal@21768
|
231 </header>
|
pascal@21768
|
232 </section>
|
pascal@21768
|
233 EOT
|
pascal@21768
|
234 xhtml_footer
|
pascal@21768
|
235 exit 0
|
pascal@21768
|
236 fi
|
pascal@18237
|
237 device="${all%|}" ;;
|
pascal@18242
|
238 *)
|
pascal@18242
|
239 cat <<EOT
|
pascal@18237
|
240 <section>
|
pascal@18237
|
241 <header>
|
pascal@18237
|
242 <form name="scanner" method="post">
|
pascal@18237
|
243 Scanner
|
pascal@18237
|
244 <select name="device" size=1>
|
pascal@18237
|
245 EOT
|
pascal@18237
|
246 echo "$all" | awk -F, '{ if (NF > 0) print "<option value=\"" $0 "\">" 1+i++ " - " $2 }'
|
pascal@18237
|
247 cat <<EOT
|
pascal@18237
|
248 </select>
|
pascal@18237
|
249 <button data-icon="start">$(_ "Continue")</button>
|
pascal@18237
|
250 </form>
|
pascal@18237
|
251 </header>
|
pascal@18237
|
252 </section>
|
pascal@18237
|
253 EOT
|
pascal@18237
|
254 xhtml_footer
|
pascal@18237
|
255 exit 0 ;;
|
pascal@18237
|
256 esac
|
pascal@18237
|
257 fi
|
pascal@18237
|
258
|
pascal@18237
|
259 cat <<EOT
|
pascal@18237
|
260 <section>
|
pascal@20172
|
261 <form name="parameters" method="post" style="width:100%">
|
pascal@18237
|
262
|
pascal@18237
|
263 <header>
|
pascal@18237
|
264 $(echo $device | sed 's/.*,//')
|
pascal@18237
|
265 <div class="float-right">
|
pascal@18237
|
266 <button name="scan" data-icon="start">$(_ "Scan")</button>
|
pascal@18242
|
267 <button name="reset" data-icon="refresh">$(_ "Reset")</button>
|
pascal@18237
|
268 <button name="preview" data-icon="view">$(_ "Preview")</button>
|
pascal@18237
|
269 </div>
|
pascal@18237
|
270 </header>
|
pascal@18237
|
271
|
pascal@20172
|
272 <table style="width:100%">
|
pascal@18237
|
273 <tr>
|
pascal@21768
|
274 <td title="Sets the file format for the scanned image">
|
pascal@18267
|
275 <fieldset><legend>$(_ 'Format')</legend>
|
pascal@18237
|
276 <select name="format" size=1>
|
pascal@18237
|
277 $(imgformat list)
|
pascal@18237
|
278 </select>
|
pascal@18267
|
279 </fieldset>
|
pascal@18237
|
280 </td>
|
pascal@18237
|
281 EOT
|
pascal@18237
|
282
|
pascal@18237
|
283 if [ "$(xPOST params)" ]; then
|
pascal@18237
|
284 params="$(xPOST params | uudecode)"
|
pascal@18237
|
285 else
|
pascal@18237
|
286 params="$({
|
pascal@18237
|
287 cat "$(echo $device | sed 's/,.*//').log" 2> /dev/null ||
|
pascal@18237
|
288 scanimage --help -d "$(echo $device | sed 's/,.*//')"
|
pascal@21768
|
289 } | dos2unix | sed 's|\[=| [|;s/||/|/g' | awk '
|
pascal@18237
|
290 function minmax()
|
pascal@18237
|
291 {
|
pascal@21768
|
292 inactive=1
|
pascal@18237
|
293 if (match($2,"[0-9]")) {
|
pascal@18237
|
294 i=$2; sub(/\.\..*/,"",i)
|
pascal@18237
|
295 j=$2; sub(/.*\.\./,"",j)
|
pascal@18237
|
296 sub(/\..*/,"",j); sub(/[dm%].*/,"",j)
|
pascal@18237
|
297 k=$0; sub(/.* \[/,"",k); sub(/\].*/,"",k)
|
pascal@21768
|
298 printf("\n%s",$1 " " int(k) " " int(i) " " int(j))
|
pascal@21768
|
299 inactive=0
|
pascal@18237
|
300 }
|
pascal@18237
|
301 }
|
pascal@18237
|
302
|
pascal@18237
|
303 function enum()
|
pascal@18237
|
304 {
|
pascal@18237
|
305 i=$0
|
pascal@21768
|
306 inactive=1
|
pascal@18237
|
307 if (index(i,"|")) {
|
pascal@21768
|
308 sub(/^ *--*[a-z-]* */,"",i)
|
pascal@21768
|
309 sub(/\[\(/,"",i); sub(/\)\]/,"",i)
|
pascal@18237
|
310 sub(/dpi .*/,"",i); gsub(/ \[.*\].*/,"",i)
|
pascal@18237
|
311 k=$0; sub(/.* \[/,"",k); sub(/\].*/,"",k)
|
pascal@18237
|
312 gsub(/ /,"=",k)
|
pascal@21768
|
313 gsub(/ /,"=",i)
|
pascal@21768
|
314 printf("\n%s",$1 " " k " enum " i)
|
pascal@21768
|
315 inactive=0
|
pascal@18237
|
316 }
|
pascal@18237
|
317 else minmax()
|
pascal@18237
|
318 }
|
pascal@18237
|
319
|
pascal@18237
|
320 {
|
pascal@21768
|
321 if (/scanimage --help/) end=1
|
pascal@21768
|
322 if (end != 0) next
|
pascal@21768
|
323 if (/:$/) parse=0
|
pascal@21768
|
324 if (/Scan mode/ || /Mode/ || /Advanced/ || /Geometry/) parse=1
|
pascal@18237
|
325 if (parse != 1) next
|
pascal@21768
|
326 if (/\[inactive\]/) { inactive=1; next }
|
pascal@18237
|
327 if (match("-l-t-x-y", $1)) minmax()
|
pascal@21768
|
328 else if (/^ --/) enum()
|
pascal@21768
|
329 else if (!/:$/ && inactive == 0) printf(" %s",$0)
|
pascal@21768
|
330 } END { print "" }
|
pascal@21768
|
331 ' | sed 1d)"
|
pascal@18237
|
332 fi
|
pascal@18242
|
333 output="$(n=$(echo "$params" | wc -l); echo "$params" | \
|
pascal@21768
|
334 while read name def min max help; do
|
pascal@21768
|
335 name="${name#-}"
|
pascal@21768
|
336 name="${name#-}"
|
pascal@21768
|
337 name="${name//-/_}"
|
pascal@21768
|
338 help="$(echo $help | sed 's| | |g;s|"|\"|g')"
|
pascal@18237
|
339 def="${def//=/ }"
|
pascal@21768
|
340 max="${max//=/ }"
|
pascal@18237
|
341 if [ "$min" == "enum" ]; then
|
pascal@18237
|
342 res_min=1000000
|
pascal@18237
|
343 res_max=0
|
pascal@21768
|
344 echo "<td title=\"$help\"><fieldset><legend>$name</legend>"
|
pascal@18237
|
345 echo -n "<select name=\"$name\" size=1"
|
pascal@18237
|
346 [ "$name" == "resolution" ] && echo -n " onchange=showGeometry()"
|
pascal@18237
|
347 echo ">"
|
pascal@18237
|
348 IFS="|"; set -- $max ; unset IFS
|
pascal@18237
|
349 while [ "$1" ]; do
|
pascal@18237
|
350 echo -n "<option value=\"$1\""
|
pascal@18237
|
351 [ "$(xPOST $name)" == "$1" ] && echo -n " selected"
|
pascal@18237
|
352 [ -z "$(xPOST $name)" -a "$def" == "$1" ] && echo -n " selected"
|
pascal@18237
|
353 echo ">$(_ "$1")"
|
pascal@18237
|
354 if [ "$name" == "resolution" ]; then
|
pascal@18237
|
355 [ $res_max -lt $1 ] && res_max=$1
|
pascal@18237
|
356 [ $res_min -gt $1 ] && res_min=$1
|
pascal@18237
|
357 fi
|
pascal@18237
|
358 shift
|
pascal@18237
|
359 done
|
pascal@18237
|
360 echo "</select>"
|
pascal@18237
|
361 else
|
pascal@18237
|
362 [ "$(xPOST $name)" ] && def=$(xPOST $name)
|
pascal@18237
|
363 [ $def -lt $min ] && def=$min
|
pascal@18237
|
364 [ $def -gt $max ] && def=$max
|
pascal@21769
|
365 f="<fieldset><legend>$(_ "$name")</legend><input type=\"range\" min=\"$min\" max=\"$max\" name=\"$name\" value=\"$def\""
|
pascal@18237
|
366 u=""
|
pascal@18237
|
367 case "$name" in
|
pascal@18237
|
368 x|y|l|t) cat <<EOT
|
pascal@18237
|
369 :${name}_max=$max
|
pascal@18237
|
370 <input type="hidden" name="${name}_min" value="$min">
|
pascal@18237
|
371 <input type="hidden" name="${name}_max" value="$max">
|
pascal@18237
|
372 EOT
|
pascal@18237
|
373 while read name2 n2 id val; do
|
pascal@18237
|
374 [ "$name" == "$name2" ] || continue
|
pascal@18237
|
375 [ "$(xPOST geometry_$name)" ] &&
|
pascal@18237
|
376 val="$(xPOST geometry_$name)"
|
pascal@18267
|
377 f="<fieldset><legend>$(_ "$n2")</legend><input name=\"geometry_$name\" id=\"$id\" value=\"$val\""
|
pascal@18237
|
378 u=" mm"
|
pascal@18237
|
379 break
|
pascal@18237
|
380 done <<EOT
|
pascal@18237
|
381 l X-Offset x 0
|
pascal@18237
|
382 t Y-Offset y 0
|
pascal@18237
|
383 x Width width $max
|
pascal@18237
|
384 y Height height $max
|
pascal@18237
|
385 EOT
|
pascal@18237
|
386 esac
|
pascal@18237
|
387 [ "$name" == "resolution" ] && f="$f onchange=showGeometry()"
|
pascal@21771
|
388 echo "<td>$f type=\"text\" title=\"$min .. $max. $help\" size=5 maxlength=5>$u"
|
pascal@18237
|
389 res_min=$min
|
pascal@18237
|
390 res_max=$max
|
pascal@18237
|
391 fi
|
pascal@18237
|
392 case "$name" in
|
pascal@18237
|
393 resolution) cat <<EOT
|
pascal@18237
|
394 <input type="hidden" name="res_min" value="$res_min">
|
pascal@18237
|
395 <input type="hidden" name="res_max" value="$res_max">
|
pascal@18237
|
396 dpi
|
pascal@18237
|
397 EOT
|
pascal@18237
|
398 esac
|
pascal@18267
|
399 echo "</filedset></td>"
|
pascal@18242
|
400 n=$(($n - 2))
|
pascal@18242
|
401 case "$n" in
|
pascal@18242
|
402 1|2) echo "</tr><tr>"
|
pascal@18242
|
403 esac
|
pascal@18237
|
404 done)"
|
pascal@18237
|
405 echo "$output" | sed '/^:/d'
|
pascal@18237
|
406
|
pascal@18237
|
407 org_x=$(xPOST geometry_x); [ "$org_x" ] || org_x=$(echo "$output" | sed '/^:x_max=/!d;s/.*=//')
|
pascal@18237
|
408 org_y=$(xPOST geometry_y); [ "$org_y" ] || org_y=$(echo "$output" | sed '/^:y_max=/!d;s/.*=//')
|
pascal@18237
|
409
|
pascal@18237
|
410 cat <<EOT
|
pascal@18237
|
411 </tr>
|
pascal@18237
|
412 </table>
|
pascal@18237
|
413 <input type="hidden" name="tmpreview" value="$tmpreview">
|
pascal@18237
|
414 <input type="hidden" name="device" value="$device">
|
pascal@18237
|
415 <input type="hidden" name="params" value="$(echo "$params" | uuencode -m -)">
|
pascal@18237
|
416 <script language="JavaScript" type="text/javascript">
|
pascal@18237
|
417 <!--
|
pascal@18237
|
418 function setGeometry(x,y) {
|
pascal@18237
|
419 document.parameters.geometry_x.value = x;
|
pascal@18237
|
420 document.parameters.geometry_y.value = y;
|
pascal@18237
|
421 cropSetFrameByInput();
|
pascal@18237
|
422 }
|
pascal@18237
|
423
|
pascal@18237
|
424 function showGeometry() {
|
pascal@18237
|
425 var resolution = document.parameters.resolution.value;
|
pascal@18237
|
426 if (resolution) {
|
pascal@18237
|
427 resolution /= 25.4;
|
pascal@18237
|
428 var x = Math.floor(document.parameters.geometry_x.value * resolution);
|
pascal@18237
|
429 var y = Math.floor(document.parameters.geometry_y.value * resolution);
|
pascal@18237
|
430 alert((Math.round(x * y / 100000)/10) + ' Mpixels\n' + x + 'x' + y);
|
pascal@18237
|
431 }
|
pascal@18237
|
432 }
|
pascal@18237
|
433 -->
|
pascal@18237
|
434 </script>
|
pascal@18237
|
435
|
pascal@18237
|
436 <footer align="center">
|
pascal@18237
|
437 EOT
|
pascal@18237
|
438 awk -vox=$org_x -voy=$org_y 'END {
|
pascal@18237
|
439 x=210*4; y=297*4; n=0; cnt=0;
|
pascal@18237
|
440 while (cnt < 9) {
|
pascal@18237
|
441 if (ox +1 >= x && oy +1 >= y) {
|
pascal@18237
|
442 print " <a href=\"javascript:setGeometry(" x "," y ")\">DIN-A" n "</a>"
|
pascal@18237
|
443 cnt++
|
pascal@18237
|
444 }
|
pascal@18237
|
445 if (ox +1 >= x && oy +1 >= y) {
|
pascal@18237
|
446 print " <a href=\"javascript:setGeometry(" y "," x ")\">DIN-A" n "L</a>"
|
pascal@18237
|
447 cnt++
|
pascal@18237
|
448 }
|
pascal@18237
|
449 tmp=x; x=y/2; y=tmp
|
pascal@18237
|
450 n++
|
pascal@18237
|
451 }
|
pascal@18237
|
452 }' < /dev/null
|
pascal@18237
|
453
|
pascal@18237
|
454 cat <<EOT
|
pascal@18237
|
455 </footer>
|
pascal@18237
|
456 </form>
|
pascal@18237
|
457 </section>
|
pascal@18237
|
458 EOT
|
pascal@18237
|
459
|
pascal@18237
|
460 [ -s "$tmpreview" ] && cat <<EOT
|
pascal@18237
|
461 <div margin="15px" style="overflow-x: auto">
|
pascal@18237
|
462 <script type="text/javascript" src="lib/crop.js"></script>
|
pascal@21769
|
463 <img src="$tmpreview" style="width:100%" onload=cropInit(this,'x','y','width','height')>
|
pascal@18237
|
464 </div>
|
pascal@18237
|
465 EOT
|
pascal@18237
|
466 xhtml_footer
|