Updates, improvements

master
Keith Irwin 2023-03-10 10:40:48 -07:00
parent 6d78d352cb
commit b504019a23
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
2 changed files with 39 additions and 71 deletions

View File

@ -23,7 +23,7 @@ sudo apt install zenity scanimage
sudo git clone https://gitea.gf4.pw/ki9/scanpix.git /usr/local/src/scanpix sudo git clone https://gitea.gf4.pw/ki9/scanpix.git /usr/local/src/scanpix
``` ```
### "Build" ### Install
```sh ```sh
sudo ln -s /usr/local/src/scanpix/scanpix /usr/local/bin/scanpix sudo ln -s /usr/local/src/scanpix/scanpix /usr/local/bin/scanpix
@ -50,7 +50,7 @@ Once a scanner is found, the user will be prompted with a gui to enter a target
If possible, always lay the photos with the shorter dimension in the same direction as the scanner travel. The scanner head will only move as far as the photo boundaries so orienting the photo correctly will significantly improve scan speeds. If possible, always lay the photos with the shorter dimension in the same direction as the scanner travel. The scanner head will only move as far as the photo boundaries so orienting the photo correctly will significantly improve scan speeds.
After scanning each photo, lay the next one and click `ok` when the prompt comes up. When you reach the last photo of that size, just click `quit` to stop scanning. The photo will be named after the [unix timestamp](https://en.wikipedia.org/wiki/Unix_time) (`"$(date +%s).jpg"`) so there shouldn't be any filename collisions. After scanning each photo, lay the next one and click `Ok` when the prompt comes up. When you reach the last photo of that size, just click `Quit` to stop scanning.
### Thunar custom actions ### Thunar custom actions
@ -71,7 +71,7 @@ If you use thunar, you might find it helpful to set up a custom action for `scan
## License ## License
**scanpix** - *Batch scan photos of the same size*\ **scanpix** - *Batch scan photos of the same size*\
Copyright © 2021 Keith Irwin [www.ki9.us](https://www.ki9.us/) Copyright © 2016-2023 Keith Irwin [www.ki9.us](https://www.ki9.us/)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

104
scanpix
View File

@ -2,7 +2,7 @@
# scanpix # scanpix
# Batch scan photos of the same size # Batch scan photos of the same size
# Copyright © 2016-2021 Keith Irwin www.ki9.us # Copyright © 2016-2023 Keith Irwin ki9.gf4.pw
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -31,7 +31,7 @@
# Default scan area in mm # Default scan area in mm
Y_SIZE="99" # width Y_SIZE="99" # width
X_SIZE="152" # height X_SIZE="151" # height
## ARGUMENTS ## ARGUMENTS
@ -39,9 +39,9 @@ if [ $# -gt 1 ]; then
echo "ERROR! Too many arguments." echo "ERROR! Too many arguments."
exit 2 exit 2
elif [ $# -eq 1 ]; then elif [ $# -eq 1 ]; then
FOLDER="$1" DIR="$1"
else else
FOLDER="$PWD" DIR="$PWD"
fi fi
@ -49,53 +49,41 @@ fi
# Find and parse scanner name # Find and parse scanner name
echo -n "Finding scanner... " echo -n "Finding scanner... "
SCANIMAGE=$(scanimage -L) SCANIMAGE="$(scanimage -L)"
SCANNER=$(echo "${SCANIMAGE:8}" | grep -oP ".*(?=')") SCANNER="$(<<<"${SCANIMAGE:8}" grep -oP ".*(?=')")"
if [ "$SCANNER" == "" ]; then if [ "${SCANNER}" == "" ]; then
echo "no scanner found!" echo "No scanner found!"
exit 3 exit 3
fi fi
echo "found." echo "found."
echo "Using scanner: $SCANNER" echo "Using scanner: $SCANNER"
# Ask user for a folder to scan into # Ask user for a directory to scan into
FOLDER=$(zenity --entry \ DIR=$(zenity --entry --title="Scan Location" \
--title="Scan Location" \
--text="Scan photos to (no trailing slash): " \ --text="Scan photos to (no trailing slash): " \
--entry-text="$FOLDER") --entry-text="${DIR}")
# User didn't enter a valid folder # User didn't enter a valid directory
if [ ! -d "$FOLDER" ]; then if [ ! -d "${DIR}" ]; then
zenity --error \ zenity --error --title="Error: Scan location not found" \
--title="Error: Scan location not found" \ --text="Couldn't find $DIR. Try again (no trailing slashes)"
--text="Couldn't find $FOLDER. Try again (no trailing slashes)"
exit 1 exit 1
else else echo "Saving photos to $DIR"; fi
echo "Saving photos to $FOLDER"
fi
# Ask for photo size # Ask for photo size
Y_SIZE=$(zenity --entry \ Y_SIZE=$(zenity --entry --title="Photo width" \
--title="Photo Width" \
--text="How wide are the photos (in mm)?" \ --text="How wide are the photos (in mm)?" \
--entry-text="$Y_SIZE") --entry-text="$Y_SIZE")
X_SIZE=$(zenity --entry \ X_SIZE=$(zenity --entry --title="Photo height" \
--title="Photo Height" \
--text="How high are the photos (in mm)?" \ --text="How high are the photos (in mm)?" \
--entry-text="$X_SIZE") --entry-text="$X_SIZE")
echo "Scanning photos at $X_SIZE x $Y_SIZE" echo "Scanning photos at $X_SIZE x $Y_SIZE"
# Wait for first photo to be placed # Wait for first photo to be placed
zenity --question \ if ! zenity --question --title="Prepare scan" \
--title="Prepare scan" \
--text="Place the first photo on the scanner and click OK" \ --text="Place the first photo on the scanner and click OK" \
--ok-label="OK" \ --ok-label="OK" --cancel-label="Quit" │
--cancel-label="Quit" │ then exit 0; fi
# Cancel
if [ ! $? = 0 ]; then
exit 0
fi
# Repeat until user cancels # Repeat until user cancels
while true; do while true; do
@ -105,46 +93,26 @@ while true; do
# Execute scan # Execute scan
NOW="$(date +%s)" NOW="$(date +%s)"
FILENAME="$FOLDER/$NOW.jpg" FILENAME="${DIR}/${NOW}.jpg"
echo -n "Scanning $NOW.jpg... " echo -n "Scanning ${NOW}.jpg... "
scanimage \ if ! scanimage \
--device-name="$SCANNER" \ --device-name="${SCANNER}" \
--mode=Color \ --mode=Color --resolution=1200 --format=tiff \
--resolution=1200 \ -x "${X_SIZE}" -y "${Y_SIZE}" \
--format=tiff \ | convert -rotate "180" tiff:- "${FILENAME}"
-x "$X_SIZE" -y "$Y_SIZE" \ then echo "FAILED!"
| convert \ if ! zenity --question --title="Scan Failed" \
-rotate "180" \
tiff:- "$FILENAME"
# Scan failed
if [ $? = 1 ]; then
echo "FAILED!"
zenity --question \
--title="Scan Failed" \
--text="That photo didn't scan correctly! What do you want to do? " \ --text="That photo didn't scan correctly! What do you want to do? " \
--ok-label="Try again" \ --ok-label="Try again" --cancel-label="Give up"
--cancel-label="Give up" then exit 1; fi
if [ ! $? = 0 ]; then
# Give up
exit 1
fi
# Scan succeeded # Scan succeeded
else else echo "Done."
echo "Done."
# Scan again? # Scan again?
zenity --question \ if ! zenity --question --title="Scan Completed" \
--title="Scan Completed" \
--text="Photo scanned to $NOW.jpg\nNow what? " \ --text="Photo scanned to $NOW.jpg\nNow what? " \
--ok-label="Scan another" \ --ok-label="Scan another" --cancel-label="Quit"
--cancel-label="Quit" then exit 0; fi
# No
if [ ! $? = 0 ]; then
exit 0
fi
fi fi
done done