#!/usr/bin/env bash # scan.sh # This will scan stuff from the scanner to the current directory # with auto-numbering as PNG. # # Usage: w=130 h=210 t=128 ./scan.sh front color 300 SCANNER="fujitsu:fi-4120Cdj:623467" # Give it your own FORMAT="png" curdir="$(pwd)" # Arguments # $1: source (front/back/duplex) - mandatory # $2: color (color/gray/grey/bw) - mandatory # $3: dpi (number) - optional function batchstart { lastindex="$(\ls | sort -n | tail -n 1 | sed 's/\..*//g')" echo $((lastindex+1)) } command="scanimage -d '$SCANNER' --format $FORMAT --batch='%d.$FORMAT' --progress --page-width $w --page-height $h --batch-start $(batchstart)" # Normalize arguments command+=" --source" case $1 in front) command+=" 'ADF Front'" ;; back) command+=" 'ADF Back'" ;; duplex) command+=" 'ADF Duplex'" ;; *) >&2 echo "invalid source";; esac case $2 in color) command+=" --mode Color --contrast 15 --brightness 25" ;; gray) command+=" --mode Gray --contrast 15 --brightness 25" ;; bw) command+=" --mode Lineart --threshold $t" ;; *) >&2 echo "invalid color";; esac if [ $3 -gt 0 ]; then command+=" --resolution $3"; else command+=" --resolution 600"; fi eval "$command"