-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan
executable file
·38 lines (36 loc) · 1.43 KB
/
scan
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
#!/bin/bash
cd tmp
function process {
uk=$1
for i in $(ls scan-$uk-*.pnm | sort -V); do
if convert $i -format "%[fx:mean>0.9999?1:0]" info: | grep -q 0; then
convert $i $i.tif && rm -f $i
else
echo "$i is blank, skipping it."
rm -f $i
fi
done
tiffcp $(ls -1 -h scan-$uk-*.tif| sort -V | xargs echo) all-$uk.tif && rm -f scan-$uk-*.tif
tesseract -l deu all-$uk.tif - pdf \
| gs -o /documents/$(date +"%Y-%m-%d-%H%M%S.pdf") -sDEVICE=pdfwrite -dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true -dColorImageResolution=36 -dGrayImageResolution=36 -dMonoImageResolution=36 -dColorImageDownsampleThreshold=1.0 -dGrayImageDownsampleThreshold=1.0 -dMonoImageDownsampleThreshold=1.0 - \
&& rm all-$uk.tif
}
while true; do
device=$(scanimage -L | grep scanner | sed "s/.*\`\(.*\)'.*/\1/g")
if [[ $device != fujitsu* ]]; then
sleep 2
continue
fi
echo "using device: $device"
break
done
while true; do
uk=$(dd if=/dev/urandom bs=2 count=2048 2>/dev/null| openssl sha1 | cut -c 21-26)
scanimage --dev "$device" --batch=scan-$uk-%d.pnm --source "ADF DUPLEX" --mode Color --resolution 300 --page-width 210 --page-height 297 -t 0 -l 0 -x 210 -y 297 --format=pnm --contrast 50 >/dev/null 2>&1
if [[ $? != 0 ]]; then
sleep 2
continue
fi
date +"%Y-%m-%d NEW JOB $uk"
process $uk &
done