]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/scan.sh
Scanner helper
[dotfiles.git] / bin / bin / scan.sh
1 #!/bin/sh
2
3 rotate=0
4 crop=0
5 cur=noname.ppm
6 ctr=${1:-1}
7 ctr=$(( $ctr - 1 ))
8
9 scan() {
10     resolution=$1
11     shift
12     scanimage --format=pnm --progress --resolution=$resolution --mode=Color $@ > tmp.ppm
13 }
14
15 process() {
16     pamflip -rotate$rotate | pnmcrop -closeness=$crop
17 }
18
19 preview() {
20     pnmscale -w 600 < tmp.ppm | process > preview.ppm
21     sxiv preview.ppm
22 }
23
24 do_next() {
25     rotate=180
26     crop=50
27     ctr=$(( $ctr + 1 ))
28     cur=`printf "%03d.ppm" $ctr`
29 }
30
31 do_next
32
33 while : ; do
34     echo "$cur: (v)iew r(otate) c(rop) (s)can (p)review (n)ext"
35     read c
36     case $c in
37     v)
38         scan 150
39         preview
40         ;;
41     s)
42         scan 1600 --high-quality=yes
43         preview
44         ;;
45     p)
46         preview
47         ;;
48     n)
49         cat tmp.ppm | process > $cur
50         do_next
51         ;;
52     r)
53         read rotate
54         echo Rotate: $rotate
55         ;;
56     c)
57         read crop
58         echo Crop: $crop
59         ;;
60     *)
61         echo ?
62         ;;
63     esac
64 done