|
|
@@ -1,9 +1,9 @@
|
|
|
#!/bin/env bash
|
|
|
|
|
|
export GDK_BACKEND=x11
|
|
|
-export SANE_DEFAULT_DEVICE='epsonds:libusb:001:005'
|
|
|
# Specify device to avoid startup delays and scanning slowness.
|
|
|
# scanimage --list-devices
|
|
|
+export SANE_DEFAULT_DEVICE='epsonds:libusb:001:005'
|
|
|
|
|
|
# See if file exists, add a number to name if needed.
|
|
|
function check_filename {
|
|
|
@@ -25,9 +25,13 @@ function check_filename {
|
|
|
export -f check_filename # Make available to run_scan's command substitution
|
|
|
|
|
|
# Run scanner. arguments:
|
|
|
-# 1-folder 2-prefix 3-timestamp 4-format
|
|
|
-# 5-papersize 6-resolution 7-iccprofile 8-colourmode
|
|
|
+# 1-folder 2-prefix 3-timestamp 4-format 5-papersize
|
|
|
+# 6-resolution 7-iccprofile 8-colourmode
|
|
|
function run_scan {
|
|
|
+ format=$4
|
|
|
+ res=$6
|
|
|
+ colmode=$8
|
|
|
+ icc=$7
|
|
|
|
|
|
# Paper sizes.
|
|
|
landscape=false
|
|
|
@@ -42,12 +46,12 @@ function run_scan {
|
|
|
x=148 y=210
|
|
|
;;
|
|
|
A5-R)
|
|
|
- if [[ $6 == "150" ]] then
|
|
|
- # Force A4 instead, and cut later.
|
|
|
- # Sane epson backend throws an out of memory error at ~A5R 150DPI.
|
|
|
+ x=210 y=148
|
|
|
+ # Force A4 instead, and cut later, if 150DPI..
|
|
|
+ # Sane epson backend throws an out of memory error at ~A5R 150DPI.
|
|
|
+ if [[ $res == "150" ]]; then
|
|
|
x=210 y=297
|
|
|
fi
|
|
|
- x=210 y=148
|
|
|
;;
|
|
|
B5)
|
|
|
x=176 y=250
|
|
|
@@ -63,35 +67,35 @@ function run_scan {
|
|
|
;;
|
|
|
esac
|
|
|
|
|
|
- filename=$1/$2-$(date +"%Y-%m-%d-%H%M%S").$4
|
|
|
+ filename=$1/$2-$(date +"%Y-%m-%d-%H%M%S").$format
|
|
|
filename=$(check_filename $filename)
|
|
|
userid=$(id -u $USER)
|
|
|
tempname="/var/run/user/$userid/temp-$(date +%s).tif"
|
|
|
|
|
|
- echo "$8 $6 $x $y $filename"
|
|
|
+ echo "$colmode $res $x $y $filename"
|
|
|
|
|
|
- scanimage --mode=$8 --resolution=$6 -x $x -y $y --format=tiff --output-file=$tempname | \
|
|
|
+ scanimage --mode=$colmode --resolution=$res -x $x -y $y --format=tiff --output-file=$tempname | \
|
|
|
yad --progress --text="Scanning (TIFF)..." --width=300 --no-buttons --auto-close
|
|
|
|
|
|
options=""
|
|
|
[[ $landscape == true ]] && options="${options} -rotate 90"
|
|
|
- [[ $7 == "Yes" ]] && options="${options} -profile /home/cinaeco/scan-dialog/scanner.icm"
|
|
|
+ [[ $icc == "Yes" ]] && options="${options} -profile /home/cinaeco/scan-dialog/scanner.icm"
|
|
|
echo "Options: $options"
|
|
|
|
|
|
convert $options $tempname $tempname | \
|
|
|
yad --progress --text="Modifying..." --width=300 --no-buttons --auto-close
|
|
|
|
|
|
- case $4 in
|
|
|
+ case $format in
|
|
|
png)
|
|
|
convert $tempname $filename | \
|
|
|
- yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
|
|
|
+ yad --progress --text="Converting to $format..." --width=300 --no-buttons --auto-close
|
|
|
;;
|
|
|
jpg)
|
|
|
convert -quality 85 $tempname $filename | \
|
|
|
- yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
|
|
|
+ yad --progress --text="Converting to $format..." --width=300 --no-buttons --auto-close
|
|
|
;;
|
|
|
pdf)
|
|
|
- if [[ $8 != "Lineart" ]] then
|
|
|
+ if [[ $colmode != "Lineart" ]]; then
|
|
|
tempname2="${tempname%.png}.jpg"
|
|
|
convert -quality 85 $tempname $tempname2 | \
|
|
|
yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
|
|
|
@@ -99,7 +103,7 @@ function run_scan {
|
|
|
tempname=$tempname2
|
|
|
fi
|
|
|
convert $tempname $filename | \
|
|
|
- yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
|
|
|
+ yad --progress --text="Converting to $format..." --width=300 --no-buttons --auto-close
|
|
|
;;
|
|
|
tiff)
|
|
|
cp $tempname $filename
|
|
|
@@ -109,7 +113,7 @@ function run_scan {
|
|
|
size_raw=$(stat -c%s $filename)
|
|
|
size_kb=$((size_raw/1024))
|
|
|
|
|
|
- yad --picture --title="Filesize: $size_kb KB ($4)" --size=fit --width=750 --height=1000 --filename=$tempname
|
|
|
+ yad --picture --title="Filesize: $size_kb KB ($format)" --size=fit --width=750 --height=1000 --filename=$tempname
|
|
|
rm $tempname
|
|
|
}
|
|
|
export -f run_scan # Make function available to yad button command.
|