mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 22:59:15 +00:00
packages/easyscan: complete rewrite
This commit is contained in:
parent
ba1167d989
commit
7f1cece74c
1 changed files with 12 additions and 58 deletions
|
|
@ -1,63 +1,17 @@
|
||||||
#
|
# This is here because scanimage's batch mode is broken for my scanner
|
||||||
# Declare variables
|
|
||||||
#
|
|
||||||
DEVICE="${SANE_DEFAULT_DEVICE:-}"
|
|
||||||
OUTPUT_FILE=
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
OUTPUT_FILE="${1:-./scan_"$(date)".pdf}"
|
||||||
case $1 in
|
|
||||||
-d | --device)
|
|
||||||
# Allows user to override the device used, since scanimage is
|
|
||||||
# slow and the printer might not even change between runs
|
|
||||||
DEVICE="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-*)
|
|
||||||
echo "Unknown option $1"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
OUTPUT_FILE="$1"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
#
|
|
||||||
# Handle defaults
|
|
||||||
#
|
|
||||||
if [ -z "$OUTPUT_FILE" ]; then
|
|
||||||
OUTPUT_FILE=./scan_"$(date)".pdf
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$DEVICE" ]; then
|
|
||||||
DEVICE=$(scanimage --formatted-device-list="%d (%v %m)" --list-devices |
|
|
||||||
fzf --header "Pick a device:" |
|
|
||||||
cut -d ' ' -f 1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
tempdir="$(mktemp -d)"
|
tempdir="$(mktemp -d)"
|
||||||
|
counter=1
|
||||||
do_scan() {
|
|
||||||
filename="$tempdir/$(date).pdf"
|
|
||||||
while ! scanimage --format=pdf --device="$DEVICE" --resolution 300 >"$filename"; do
|
|
||||||
:
|
|
||||||
done
|
|
||||||
echo "$filename"
|
|
||||||
}
|
|
||||||
|
|
||||||
do_fix() {
|
|
||||||
read -r filename
|
|
||||||
fixed_name="${filename%.pdf}_fixed.pdf"
|
|
||||||
gs -o "$fixed_name" -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress "$filename"
|
|
||||||
rm "$filename"
|
|
||||||
mv "$fixed_name" "$filename"
|
|
||||||
echo "$filename"
|
|
||||||
}
|
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
do_scan | do_fix
|
# If no size is set, the output will be wonky-sized
|
||||||
|
# 210,297 is the size of A4
|
||||||
|
scanimage -x 210 -y 297 --resolution 300 -o "$tempdir/easyscan_$counter.pdf" ||
|
||||||
|
{
|
||||||
|
echo "Failed to scan page..."
|
||||||
|
}
|
||||||
|
|
||||||
IFS= read -r -p "Continue scanning? [Y/n] " cont
|
IFS= read -r -p "Continue scanning? [Y/n] " cont
|
||||||
case "$cont" in
|
case "$cont" in
|
||||||
|
|
@ -67,12 +21,12 @@ while :; do
|
||||||
;;
|
;;
|
||||||
[yY] | *) ;;
|
[yY] | *) ;;
|
||||||
esac
|
esac
|
||||||
|
counter=$((counter += 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
# Multiple files are scanned, join them
|
# Multiple files are scanned, join them
|
||||||
merged_filename="$tempdir/$(date)_final.pdf"
|
merged_filename="$tempdir/easyscan_final.pdf"
|
||||||
pdfunite "$tempdir"/*.pdf "$merged_filename"
|
pdfunite "$tempdir"/*.pdf "$merged_filename"
|
||||||
echo "$merged_filename" | do_fix
|
|
||||||
|
|
||||||
# Copy scan to current directory
|
# Copy scan to current directory
|
||||||
cp "$merged_filename" "$OUTPUT_FILE"
|
cp "$merged_filename" "$OUTPUT_FILE"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue