#!/bin/bash # 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" resize_pdf="-page Letter" PROG_NAME=$(basename $0) print_usage() { 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 } while getopts "chjpq:r:" flag ;do case ${flag} in c) color_mode="Color" ;; j) extension="jpg" resize_pdf="" ;; 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 echo "${PROG_NAME}: Nom de fichier manquant." echo "Essayez \`${PROG_NAME} -h' pour plus d'informations." exit 1 fi src=${1} scanimage --format=pnm --mode ${color_mode} --resolution ${resolution} ${scan_area} | \ convert - -compress jpeg -quality ${jpeg_quality} ${resize_pdf} \ ${src}.${extension}