| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/bin/env bash
- export GDK_BACKEND=x11
- export SANE_DEFAULT_DEVICE='epsonds:libusb:001:006' # Specify device to avoid startup delays and scanning slowness.
- function check_filename {
- path=$1
- folder=$(dirname "$path")
- file=$(basename "$path")
- extension="${file##*.}"
- filename="${file%.*}"
- if [[ -e "$path" ]]; then
- i=2
- while [[ -e "$folder/$filename-$i.$extension" ]]; do
- let i++
- done
- filename=$filename-$i
- fi
- echo "$folder/$filename.$extension"
- }
- export -f check_filename # Make available to run_scan's command substitution
- # positional arguments: 1-folder 2-prefix 3-format 4-papersize 5-resolution 6-colormode
- function run_scan {
- # Paper size.
- case $4 in
- A4)
- x=210
- y=297
- ;;
- A5)
- x=148
- y=210
- ;;
- A5R)
- x=210 # currently removed A5R because sane epson backend throws an out of memory error.
- y=148
- ;;
- esac
- filename=$(check_filename $1/$2.$3)
- echo "$6 $5 $x $y $filename"
- tempname="./temp-$(date +%s).png"
- scanimage --mode=$6 --resolution=$5 -x $x -y $y --format=png --output-file=$tempname | \
- yad --progress --text="Scanning to PNG..." --width=300 --no-buttons --auto-close
- case $3 in
- png)
- mv $tempname $filename
- ;;
- jpg)
- convert -quality 85 $tempname $filename | \
- yad --progress --text="Converting to $3..." --width=300 --no-buttons --auto-close
- rm $tempname
- ;;
- pdf)
- if [[ $6 != "Lineart" ]] then
- tempname2="${tempname%.png}.jpg"
- convert -quality 85 $tempname $tempname2 | \
- yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
- rm $tempname
- tempname=$tempname2
- fi
- convert $tempname $filename | \
- yad --progress --text="Converting to $3..." --width=300 --no-buttons --auto-close
- rm $tempname
- ;;
- esac
- }
- export -f run_scan # Make function available to yad button command.
- # Display scan-dialog.
- yad --form --orient=hor --maximized --width=750 --height=250 --columns=3 \
- --title="Scanning Options" \
- --field="Scan Folder:SFL" /mnt/public \
- --field="Filename Prefix:SFL" scan \
- --field="File format:CB" jpg\!png\!pdf \
- --field="Paper Size:CB" A4\!A5 \
- --field="Resolution (DPI):CB" 75\!^150\!300\!600\!1200 \
- --field="Scan Buttons:BTN" "" \
- --field="Colour:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 Color"' \
- --field="Grayscale:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 Gray"' \
- --field="B&W:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 Lineart"' \
- --field="...:BTN" "" \
- --field="Presets:BTN" "" \
- --field="Art (Colour PNG):FBTN" 'bash -c "run_scan %1 art png %4 %5 Color"' \
- --field="Art (Colour JPG):FBTN" 'bash -c "run_scan %1 art jpg %4 %5 Color"' \
- --field="Doc (Gray PDF):FBTN" 'bash -c "run_scan %1 doc pdf %4 %5 Gray"' \
- --field="Doc (B&W PDF):FBTN" 'bash -c "run_scan %1 doc pdf %4 %5 Lineart"' \
- --no-buttons --buttons-layout=center
|