Ajout lighttpd (fonctionne avec PHP5)
[hvlinux.git] / stage2 / hv-utilities / hv-scan
index 939cf5d..6398599 100755 (executable)
@@ -1,24 +1,77 @@
 #!/bin/bash
 
-JPEG_QUALITY=10
+# Numérisation d'un document texte, et conversion en PDF
+
+jpeg_quality=10
+color_mode="Gray"
+resolution="200"
+extension="pdf"
+scan_area="--scan-area Letter"
+PROG_NAME=$(basename $0)
 
 print_usage()
 {
-    echo "$(basename $0) -- Numérisation image monochrome 8.5\"x11\" en PDF"
-    echo "Usage: $(basename $0) [OPTIONS...] FICHIER"
+    echo "${PROG_NAME} -- Numérisation document 8.5\"x11\" en PDF"
+    echo "Usage: ${PROG_NAME} [OPTIONS...] FICHIER"
+    echo
+    echo "Options:"
+    echo "  -c   numérisation en couleur (défaut = noir et blanc)"
+    echo "  -h   display this help and exit"
+    echo "  -j   format de sortie JPEG (défaut = PDF)"
+    echo "  -q   qualité JPEG (défaut = 10)"
+    echo "            1 = basse qualité"
+    echo "          100 = haute qualité"
+    echo "  -r   résolution (défaut = 200 DPI)"
+    echo "  -p   taille photo, 8.5\"x5.5\" (défaut = 8.5\"x11\")"
+    echo
 }
 
-if [ "x${1}" = "x--help" ]; then
-    print_usage
+while getopts "chjpq:r:" flag ;do
+    case ${flag} in
+       c)
+           color_mode="Color"
+           ;;
+       j)
+           extension="jpg"
+           ;;
+       h)
+           print_usage
+            exit 0
+           ;;
+       p)
+           scan_area="-l 0 -t 0 -x 215.9 -y 150"
+           ;;
+       q)
+            jpeg_quality=${OPTARG}
+           ;;
+       r)
+            # JPEG resolution
+            resolution=${OPTARG}
+           ;;
+       ?)
+           echo "${PROG_NAME}: Option invalide: ${OPTARG}."
+           echo "Essayez \`${PROG_NAME} -h' pour plus d'informations."
+           exit 1
+           ;;
+    esac
+done
+shift `expr "${OPTIND}" - 1`
+
+# `$#' now represents the number of arguments after the options.
+# `$1' is the first argument, etc.
+if [ $# -gt 1 ]; then
+    echo "${PROG_NAME}: Too many arguments."
+    echo "Essayez \`${PROG_NAME} -h' pour plus d'informations."
     exit 1
 fi
 
 if [ ${#} -ne 1 ]; then
-    print_usage
+    echo "${PROG_NAME}: Nom de fichier manquant."
+    echo "Essayez \`${PROG_NAME} -h' pour plus d'informations."
     exit 1
 fi
 
 src=${1}
 
-scanimage --mode Gray --resolution 200 --scan-area Letter | \
-    convert - -compress jpeg -quality ${JPEG_QUALITY} ${src}.pdf
+scanimage --mode ${color_mode} --resolution ${resolution} ${scan_area} | \
+    convert - -compress jpeg -quality ${jpeg_quality} ${src}.${extension}