aboutsummaryrefslogtreecommitdiffstats
path: root/hm/soispha/pkgs/scripts/apps
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-11-25 15:51:33 +0100
committerSoispha <soispha@vhack.eu>2023-11-25 15:51:33 +0100
commitec76bfb05f0b91001be58cd481a0889231390751 (patch)
tree1e8ceb24e8bfeafa36750419c0a4a9ffc2400438 /hm/soispha/pkgs/scripts/apps
parentbuild(treewide): Update shell library (diff)
downloadnixos-config-ec76bfb05f0b91001be58cd481a0889231390751.zip
fix(hm/pkgs/src/con2pdf): Fully support n pages, instead of 2
Diffstat (limited to 'hm/soispha/pkgs/scripts/apps')
-rwxr-xr-xhm/soispha/pkgs/scripts/apps/con2pdf48
1 files changed, 30 insertions, 18 deletions
diff --git a/hm/soispha/pkgs/scripts/apps/con2pdf b/hm/soispha/pkgs/scripts/apps/con2pdf
index 04ce7ce8..f5b3623e 100755
--- a/hm/soispha/pkgs/scripts/apps/con2pdf
+++ b/hm/soispha/pkgs/scripts/apps/con2pdf
@@ -62,7 +62,7 @@ EOF
scan() {
number_of_pages="$1";
device="$2";
- output_directory="$3";
+ output_directory="$(readlink -f "$3")";
name="$4";
method="$5";
@@ -77,9 +77,15 @@ scan() {
msg "Started scanning...";
if [ "$method" = "Flatbed" ]; then
- do_until_success \
- "scanimage --format=tiff --progress --source='$method' --device='$device' --output-file=1.tiff" \
- "warn 'Retrying scan, as we assume a network error!'"
+ for i in $(seq "$number_of_pages"); do
+ do_until_success \
+ "scanimage --format=tiff --progress --source='$method' --device='$device' --output-file=$i.tiff" \
+ "warn 'Retrying scan, as we assume a network error!'"
+ if [ "$number_of_pages" -ne 1 ];then
+ msg "Finished turn, please change side!";
+ readp "Press enter to continue" noop
+ fi
+ done
else
for i in $(seq "$number_of_pages");do
do_until_success \
@@ -99,27 +105,33 @@ scan() {
cd "$output_directory" || die "Bug"
counter=0;
+ image_cache="$(mktmp)"
msg "Converting images to pdfs...";
- while read -r scanned_image_a;do
- if [ "$number_of_pages" -ne 1 ];then
- scanned_image_b_set=false;
- if [ -z "$scanned_image_b" ];then
- scanned_image_b="$i"
- scanned_image_b_set=true;
- : $((counter += 1))
- fi
-
- if [ -n "$scanned_image_a" ] && [ "$scanned_image_b_set" = false ];then
- convert "$scanned_image_b" "$scanned_image_a" -compress jpeg -quality 100 "$name"_"$counter".pdf
- fi
+ while read -r scanned_image;do
+ if [ "$counter" = "$number_of_pages" ]; then
+ counter=0;
+ process_images "$image_cache" "$name" "$output_directory"
+ echo "" > "$image_cache"
else
+ echo "$scanned_image" >> "$image_cache"
: $((counter += 1))
- convert "$scanned_image_a" -compress jpeg -quality 100 "$name"_"$counter".pdf
fi
-
done < "$(tmp fd . "$tiff_temp_path" "|" sort -n)"
}
+process_images() {
+ image_cache="$1";
+ name="$2";
+ output_dir="$3";
+
+ set -- ""
+ while read -r image; do
+ set -- "$@" "$image"
+ done < "$image_cache"
+
+ convert "$@" -compress jpeg -quality 100 "$output_dir/${name}_${counter}.pdf"
+}
+
for input in "$@"; do
case "$input" in
"--help" | "-h")