mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-04 16:07:59 +00:00
Revert "Merge pull request 'Rewrite easyscan in haskell' (#31) from easyscan2 into trunk"
This reverts commitb3fb8aff73, reversing changes made toa7aa536cf6.
This commit is contained in:
parent
56cb062447
commit
25df5b3993
5 changed files with 76 additions and 148 deletions
61
nix/packages/by-name/easyscan/easyscan.sh
Normal file
61
nix/packages/by-name/easyscan/easyscan.sh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# This is here because scanimage's batch mode is broken for my scanner
|
||||
|
||||
OUTPUT_FILE="${1:-./scan_"$(date)".pdf}"
|
||||
|
||||
if [ -e "$OUTPUT_FILE" ]; then
|
||||
echo "$OUTPUT_FILE" already exists, you are probably making a mistake!
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tempdir="$(mktemp -d)"
|
||||
filenames=()
|
||||
counter=1
|
||||
|
||||
function clean() {
|
||||
# Make sure I don't remove things other than pdf
|
||||
rm "$tempdir/"*.pdf
|
||||
rm -d "$tempdir"
|
||||
}
|
||||
trap clean EXIT
|
||||
|
||||
while :; do
|
||||
ok="true"
|
||||
echo "Scanning page $counter"
|
||||
|
||||
CUR_FNAME="$tempdir/easyscan_$counter.pdf"
|
||||
|
||||
# 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 "$CUR_FNAME" >/dev/null 2>&1 ||
|
||||
{
|
||||
echo "Failed to scan page..."
|
||||
ok="false"
|
||||
}
|
||||
|
||||
if $ok; then
|
||||
counter=$((counter += 1))
|
||||
filenames+=("$CUR_FNAME")
|
||||
fi
|
||||
|
||||
IFS= read -r -p "Continue scanning? [Y/n] " cont
|
||||
case "$cont" in
|
||||
[nN])
|
||||
echo "Exiting..."
|
||||
break
|
||||
;;
|
||||
[yY] | *) ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Multiple files are scanned, join them
|
||||
#
|
||||
# Note: do NOT use the * glob, because bash orders lexicographically and not
|
||||
# numerically, the merged ordering will be wrong.
|
||||
merged_filename="$tempdir/easyscan_final.pdf"
|
||||
pdfunite "${filenames[@]}" "$merged_filename"
|
||||
|
||||
# Copy scan to current directory
|
||||
mkdir -p "$(dirname "$OUTPUT_FILE")"
|
||||
cp "$merged_filename" "$OUTPUT_FILE"
|
||||
|
||||
clean
|
||||
Loading…
Add table
Add a link
Reference in a new issue