wok-6.x rev 18242

sane-backends/sane.cgi: resize to screen width in preview
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 29 17:07:24 2015 +0200 (2015-07-29)
parents f630a53bd713
children c50866b1c9cb
files sane-backends/receipt sane-backends/stuff/tazpanel/sane sane-backends/stuff/tazpanel/sane.cgi
line diff
     1.1 --- a/sane-backends/receipt	Tue Jul 28 10:56:38 2015 +0000
     1.2 +++ b/sane-backends/receipt	Wed Jul 29 17:07:24 2015 +0200
     1.3 @@ -40,6 +40,7 @@
     1.4  	mkdir -p $fs/usr/lib $fs/usr/share \
     1.5  	         $fs/var/lock/sane $fs/etc/sane.d \
     1.6  	         $fs/var/www/tazpanel/lib \
     1.7 +	         $fs/var/www/tazpanel/report.d \
     1.8  	         $fs/var/www/tazpanel/menu.d/hardware
     1.9  	
    1.10  	cp -a $install/etc/sane.d $fs/etc
    1.11 @@ -49,6 +50,7 @@
    1.12  	cp -a $install/usr/lib/sane $fs/usr/lib
    1.13  	cp -a $install/usr/share/sane $fs/usr/share
    1.14  	cp $stuff/tazpanel/sane.cgi $fs/var/www/tazpanel/
    1.15 +	cp $stuff/tazpanel/sane $fs/var/www/tazpanel/report.d/
    1.16  	cp $stuff/tazpanel/crop.js $fs/var/www/tazpanel/lib/
    1.17  	ln -s ../../sane.cgi $fs/var/www/tazpanel/menu.d/hardware/sane
    1.18  	
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/sane-backends/stuff/tazpanel/sane	Wed Jul 29 17:07:24 2015 +0200
     2.3 @@ -0,0 +1,5 @@
     2.4 +	cat <<EOT
     2.5 +<h2>scanimage --help</h2>
     2.6 +<pre>$(scanimage --help 2>&1)</pre>
     2.7 +
     2.8 +EOT
     3.1 --- a/sane-backends/stuff/tazpanel/sane.cgi	Tue Jul 28 10:56:38 2015 +0000
     3.2 +++ b/sane-backends/stuff/tazpanel/sane.cgi	Wed Jul 29 17:07:24 2015 +0200
     3.3 @@ -37,11 +37,12 @@
     3.4      
     3.5  getgeometry() {
     3.6  	CMD=""
     3.7 -	for i in l t x y ; do
     3.8 +	ARGS=""
     3.9 +	for i in x y l t ; do
    3.10  		j=$(inrange $(xPOST geometry_$i) $(xPOST ${i}_min) $(xPOST ${i}_max))
    3.11  		eval "geometry_$i=$j"
    3.12  		CMD="$CMD -$i $j"
    3.13 -# convert -crop XxY+L+T -resize XxY
    3.14 +		ARGS="$ARGS $j"
    3.15  	done
    3.16  	for i in mode source contrast brightness ; do
    3.17  		[ "$(xPOST $i)" ] && CMD="$CMD --$i '$(xPOST $i)'"
    3.18 @@ -55,10 +56,35 @@
    3.19  			resolution=$(($resolution * 2))
    3.20  		done
    3.21  	fi
    3.22 +	case "$(xPOST mode)" in
    3.23 +	*lack*|*ineart*) mode="-monochrome" ;;
    3.24 +	*ray*) mode="-colorspace gray" ;;
    3.25 +	*) mode="" ;;
    3.26 +	esac
    3.27  	[ -d tmp ] || ln -s /tmp tmp
    3.28  	case "$device" in
    3.29 -	fake*)	echo "cat /usr/share/images/slitaz-background.jpg" ;;
    3.30 -	*)	echo "scanimage -d '$(echo $device | sed 's/,.*//')' --resolution '$(inrange $resolution $(xPOST res_min) $(xPOST res_max))dpi'$CMD"
    3.31 +	fake*)	f=/usr/share/images/slitaz-banner.png
    3.32 +		c="$(echo $ARGS $(identify $f | sed \
    3.33 +		    's/.* \([0-9]*\)x.*/\1/') $(GET width) $(POST x_max) | awk '
    3.34 +function a(x) { return int(($x * $5)/ $7); }
    3.35 +{ printf "%dx%d+%d+%d -resize %dx%d",a(1),a(2),a(3),a(4),$6,int(($2*$6)/$1)}
    3.36 +')"
    3.37 +		cat <<EOT
    3.38 +if convert -crop $c $mode $f /tmp/sane$$.png 2> /dev/null ; then
    3.39 +	cat /tmp/sane$$.png
    3.40 +	rm -f /tmp/sane$$.png
    3.41 +else
    3.42 +	cat $f
    3.43 +fi
    3.44 +EOT
    3.45 +		;;
    3.46 +	*)	echo -n "scanimage -d '$(echo $device | sed 's/,.*//')' --resolution '$(inrange $resolution $(xPOST res_min) $(xPOST res_max))dpi'$CMD"
    3.47 +		if [ -z "$1" -a "$(which convert)" ]; then
    3.48 +			echo -n "> /tmp/sane$$.pnm ; convert -resize "
    3.49 +			echo $ARGS $(GET width) | awk '{ printf "%dx%d",$5,int(($2*$5)/$1)}'
    3.50 +			echo -n " /tmp/sane$$.pnm /tmp/sane$$.png ;"
    3.51 +			echo -n "cat /tmp/sane$$.png ; rm -f /tmp/sane$$.pn?"
    3.52 +		fi
    3.53  	esac
    3.54  }
    3.55  
    3.56 @@ -151,20 +177,31 @@
    3.57  xhtml_header
    3.58  [ -n "$error" ] && msg warn "$error"
    3.59  [ -n "$info" ] && msg tip "$info"
    3.60 -[ "$(which convert 2> /dev/null)" ] ||
    3.61 -msg tip "$(_ "You should install %s to preview images." \
    3.62 -	     "<a href=\"/user/pkgs.cgi?info=imagemagick\">imagemagick</a>")"
    3.63  if [ -z "$device" ]; then
    3.64 -	[ -s sane-fake.log ] && all="$(sed 's/|/\n/g' sane-fake.log)" ||
    3.65 -	all="$(scanimage -f '%d,%v %m|' | sed 's/|/\n/g')"
    3.66 +	all="$(scanimage -f '%d,%v %m|'|cat - sane-fake.log|sed 's/|/\n/g')"
    3.67  	case "$(echo "$all" | wc -l)" in
    3.68  	1)	if [ -z "$all" ]; then
    3.69 -			msg warn 'No scanner found'
    3.70 +			msg warn "$(_ "No scanner found")"
    3.71 +			msg tip "$(_ "You can test this GUI with ")\
    3.72 +<a href=\"/user/pkgs.cgi?info=fake-sane\">fake-sane</a>"
    3.73  			xhtml_footer
    3.74  			exit 0
    3.75  		fi
    3.76  		device="${all%|}" ;;
    3.77 -	*)	cat <<EOT
    3.78 +	*)
    3.79 +		suggested=""
    3.80 +		while read exe pkg msg; do
    3.81 +			[ "$(which $exe 2> /dev/null)" ] && continue
    3.82 +			suggested="$suggested
    3.83 +<li><a href=\"/user/pkgs.cgi?info=$pkg\">$pkg</a>&nbsp;$msg</li>"
    3.84 +		done <<EOT
    3.85 +convert		imagemagick	$(_ "to preview images and support more image formats")
    3.86 +gocr		gocr		$(_ "a basic optical character recognition")
    3.87 +tesseract	tesseract-ocr	$(_ "a better optical character recognition")
    3.88 +EOT
    3.89 +		[ "$suggested" ] &&
    3.90 +		msg tip "$(_ "You may need to install:") <ol>$suggested</ol>"
    3.91 +		cat <<EOT
    3.92  <section>
    3.93  	<header>
    3.94  		<form name="scanner" method="post">
    3.95 @@ -190,7 +227,7 @@
    3.96  <script language="JavaScript" type="text/javascript">
    3.97  <!--
    3.98  function new_width() {
    3.99 -	document.parameters.action = "?width="+document.width
   3.100 +	document.parameters.action = "?width="+(document.width-30)
   3.101  }
   3.102  
   3.103  window.onresize = new_width
   3.104 @@ -202,7 +239,7 @@
   3.105  $(echo $device | sed 's/.*,//')
   3.106  <div class="float-right">
   3.107  	<button name="scan" data-icon="start">$(_ "Scan")</button>
   3.108 -	<button name="reset" data-icon="stop">$(_ "Reset")</button>
   3.109 +	<button name="reset" data-icon="refresh">$(_ "Reset")</button>
   3.110  	<button name="preview" data-icon="view">$(_ "Preview")</button>
   3.111  </div>
   3.112  </header>
   3.113 @@ -256,7 +293,8 @@
   3.114  }
   3.115  ')"
   3.116  fi
   3.117 -output="$(echo "$params" | while read name def min max ; do
   3.118 +output="$(n=$(echo "$params" | wc -l); echo "$params" | \
   3.119 +while read name def min max ; do
   3.120  	name="${name##*-}"
   3.121  	def="${def//=/ }"
   3.122  	if [ "$min" == "enum" ]; then
   3.123 @@ -283,7 +321,7 @@
   3.124  		[ "$(xPOST $name)" ] && def=$(xPOST $name)
   3.125  		[ $def -lt $min ] && def=$min
   3.126  		[ $def -gt $max ] && def=$max
   3.127 -		f="$(_ "$name")<input name=\"$name\" value=\"$def\""
   3.128 +		f="$(_ "$name") <input name=\"$name\" value=\"$def\""
   3.129  		u=""
   3.130  		case "$name" in
   3.131  		x|y|l|t) cat <<EOT
   3.132 @@ -304,8 +342,6 @@
   3.133  x	Width		width	$max
   3.134  y	Height		height	$max
   3.135  EOT
   3.136 -			[ "$newline" ] || echo "</tr><tr>"
   3.137 -			newline=$name
   3.138  		esac
   3.139  		[ "$name" == "resolution" ] && f="$f onchange=showGeometry()"
   3.140  		echo "<td>$f type=\"text\" title=\"$min .. $max\" size=4 maxlength=4>$u"
   3.141 @@ -320,6 +356,10 @@
   3.142  EOT
   3.143  	esac
   3.144  	echo "</td>"
   3.145 +	n=$(($n - 2))
   3.146 +	case "$n" in
   3.147 +	1|2) echo "</tr><tr>"
   3.148 +	esac
   3.149  done)"
   3.150  echo "$output" | sed '/^:/d'
   3.151