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