-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan-lide
executable file
·60 lines (54 loc) · 1.59 KB
/
scan-lide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
scan() {
[ $# -ge 1 ] || exit 1
OUT="$1"
shift
DPI="${1:-300dpi}"
WIDTH="${2:-214}"
HEIGHT="${3:-295}"
DEVICE=pixma
if [ -z "${1}" ]; then
scanimage --device $DEVICE --format=png --output-file "$OUT" -l2 -t 2 -x "$WIDTH" -y "$HEIGHT" --resolution "$DPI" --button-controlled=yes
else
scanimage --device $DEVICE --format=png --output-file "$OUT" -x "$WIDTH" -y "$HEIGHT" --resolution "$DPI" --button-controlled=yes
fi
}
autocrop() {
[ $# -ge 1 ] || exit 1
TMP=`mktemp`
ORIG="$1"
INFO=`convert "${ORIG}" -virtual-pixel edge -blur 0x15 -fuzz 5% -trim +repage -format '%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]' info:`
convert "${ORIG}" -crop "$INFO" +repage ${TMP}
mv "${TMP}" "${ORIG}"
}
ctrl_c() {
exit 0
}
scan_loop() {
if [ -z "${2}" ]; then
echo "Press scanner button to scan each image at "${1:-300dpi}". (auto-crop enabled)" >&2
else
echo "Press scanner button to scan each image at "${1:-300dpi}". (manual size disabled auto-crop)" >&2
fi
for x in {001..999}; do
[ -s "${x}.png" ] || {
scan "${x}.png" "$@"
if [ -z "${2}" ]; then
autocrop "${x}.png"
fi
echo "Press scanner button to scan next image" >&2
# beep # feel free to enable, all beeps are disabled on my system anyway.
}
done
}
if [ "$1" == "-h" ]; then
echo "Usage: scan-lide [DPI] [WIDTH-MM] [HEIGHT-MM]"
echo " ex scan-lide 600dpi 195 155 # (leuchtterm size)"
exit 0
fi
if which scanimage >/dev/null 2>/dev/null; then :; else
echo "Missing program: scanimage" >&2
echo "Run: pacman -S sane" >&2
exit 1
fi
scan_loop "$@"