#!/bin/sh rotate=0 crop=0 cur=noname.ppm ctr=${1:-1} ctr=$(( $ctr - 1 )) scan() { preview=$1 shift [ -z "$NEGATIVE" ] && src="Flatbed" || src="Transparency Adapter" [ -z "$NEGATIVE" ] && depth=8 || depth=16 [ -z "$NEGATIVE" ] && resolution=800 || resolution=1600 if [ "$preview" = "yes" ]; then depth=8 resolution=150 fi scanimage \ --format=pnm \ --mode=Color \ --depth $depth \ --progress \ --resolution=$resolution \ --source="$src" \ $@ > tmp.ppm } process() { [ $rotate -eq 0 ] && rotator=cat || rotator="pamflip -rotate$rotate" [ -z "$NEGATIVE" ] && inverter=cat || inverter=pnminvert $rotator | pnmcrop -closeness=$crop | $inverter } preview() { process < tmp.ppm | pamdepth 255 | pnmscale -w 600 > preview.ppm sxiv preview.ppm } do_next() { rotate=180 [ -z "$NEGATIVE" ] && crop=40 || crop=10 ctr=$(( $ctr + 1 )) cur=`printf "%03d.ppm" $ctr` } do_next while : ; do echo -n "$cur: crop:$crop rotate:$rotate v/r/c/s/p/n> " read c case $c in v) scan yes --preview=yes preview ;; s) scan no --preview=no --high-quality=yes preview ;; p) preview ;; n) cat tmp.ppm | process > $cur do_next ;; r) echo -n "Rotate (n/r/l/t):" read rotate case $rotate in n) rotate=180 ;; r) rotate=90 ;; l) rotate=270 ;; t) rotate=0 ;; *) echo ? ;; esac ;; c) echo -n Crop: read crop ;; *) echo ? ;; esac done