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
```
### "Build"
### Install
```sh
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.
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
@ -71,7 +71,7 @@ If you use thunar, you might find it helpful to set up a custom action for `scan
## License
**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.

104
scanpix
View File

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