-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_process_folder.sh
executable file
·82 lines (63 loc) · 2.07 KB
/
image_process_folder.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# This is the server-side processing script for incoming scans
# Manual rotation should be done before this runs.
folder="$1"
install_base=`dirname "$0"`
if [ "${install_base}" == "." ]; then
install_base=`pwd`
fi
last_dpi=300
echo "${install_base}"
PATH="$PATH:${install_base}"
if [ -d $folder ]; then
pushd $folder > /dev/null
scan_folder=`pwd`
popd > /dev/null
pushd ${scan_folder} > /dev/null
for scan in *.tif; do
# If it's too big, shrink it
file_size=$(stat -c%s $scan)
dpi=`tiffinfo "${scan}" | grep "Resolution:" | sed -e 's/ Resolution: //' | awk -F "," '{print $1}'`
if [ "$dpi" == "" ]; then
dpi=${last_dpi}
else
last_dpi=${dpi}
fi
maxsize=$(( $dpi * $dpi * 15 ))
# 600 dpi = 5000000
# 300 dpi = 1250000
if ((( $file_size > $maxsize ))); then
echo "Compressing huge image..."
nice mogrify -monochrome $scan
fi
# Remove Blank Pages
#image_isblank.sh "$scan" --delete
image_isblank.sh "$scan"
# Remove Black Pages
#image_isblack.sh "$scan" --delete
image_isblack.sh "$scan"
echo "Processing image $scan :"
# If page was blank, the rest doesn't matter
if [ -f $scan ]; then
# Find Barcodes
echo " Scanning for bar codes..."
image_barcode.sh "$scan"
# Straighten
echo " Straigtening..."
image_deskew.sh "$scan"
# OCR
# echo " Extracting text..."
# image_ocr.sh all "$scan"
# Thumbnail
echo " Creating thumbnail..."
image_thumbnail.sh "$scan"
echo " Compressing..."
# Compress using LZW (saves ~80% space)
image_shrink.sh "$scan"
echo " Done."
else
echo "Blank Page $scan removed."
fi
done
popd > /dev/null
fi