Created
March 12, 2016 03:40
-
-
Save triple-j/3607abec035d9a2aff51 to your computer and use it in GitHub Desktop.
batch scanner for `scanimage`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## variables ## | |
NUM=0 | |
PRE="" | |
X="" | |
Y="" | |
RES="" | |
QAL="" | |
REV="" | |
ZEROS=4 | |
#if [ "$1" == "" ]; then | |
# echo "append '--help' for more information" | |
# exit 1 | |
#fi | |
while [ "$1" != "" ]; do | |
case "$1" in | |
--help) | |
echo "Usage: ${0##*/} [OPTION]..." | |
echo " --help show this help file" | |
echo " --start number to start at" | |
echo " --prefix what to start the filename with" | |
echo " -x width of scan-area (in mm)" | |
echo " -y height of scan-area (in mm)" | |
echo " --resolution the resolution of the scanned image (in dpi)" | |
echo " --quality jpeg quality (worst 0 - 100 best" | |
echo " --reverse the back of the image must also be scanned" | |
exit 1 | |
;; | |
--start) | |
shift | |
NUM=$1 | |
;; | |
--prefix) | |
shift | |
PRE="$1" | |
;; | |
-x) | |
shift | |
X=$1 | |
;; | |
-y) | |
shift | |
Y=$1 | |
;; | |
--resolution) | |
shift | |
RES=$1 | |
;; | |
--quality) | |
shift | |
QAL=$1 | |
;; | |
--reverse) | |
REV="b" | |
;; | |
esac | |
shift | |
done | |
KEY="" | |
while [ "$KEY" != "q" ]; do | |
# switch to reverse side | |
if [ "$REV" == "a" ]; then | |
REV="b" | |
NUM=$((NUM-1)) | |
elif [ "$REV" == "b" ]; then | |
REV="a" | |
fi | |
# add zeros to the beginning of the number | |
STRNUM="$NUM" | |
while [ ${#STRNUM} -lt $ZEROS ]; do | |
STRNUM="0$STRNUM" | |
done | |
# set filename | |
if [ "$PRE" != "" ]; then | |
FILE="${PRE}-${STRNUM}${REV}.jpg" | |
else | |
FILE="${STRNUM}${REV}.jpg" | |
fi | |
# set scanner options | |
SOPTS="--compression none" | |
if [ "$RES" != "" ]; then | |
SOPTS="$SOPTS --resolution $RES" | |
fi | |
if [ "$X" != "" ]; then | |
SOPTS="$SOPTS -x $X" | |
fi | |
if [ "$Y" != "" ]; then | |
SOPTS="$SOPTS -y $Y" | |
fi | |
# set converter options | |
COPTS="" | |
if [ "$QAL" != "" ]; then | |
COPTS="-quality $QAL" | |
fi | |
# scan image | |
echo "Scanning: $FILE" | |
scanimage $SOPTS | convert - $COPTS "$FILE" | |
# increase number | |
NUM=$((NUM+1)) | |
# wait | |
beep # audible clue | |
read -n 1 -p "Press any key to continue... (q to Quit)" KEY | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment