add option to not post-process pictures

This commit is contained in:
Tilman Kranz 2024-07-15 08:10:04 +02:00
parent dc4c5498b2
commit 822b984678

View File

@ -48,7 +48,7 @@ sigmoidal_contrast="45,50%"
posterize=6
# Keep intermediate images after processing
keep_tmpfiles=true
keep_tmpfiles=false
# Paper size of all pages
paper="a4paper"
@ -111,8 +111,14 @@ Arguments
---------
* `DIR`: Directory containing the original photos.
Options
-------
General Options
---------------
* `--help`: Print this message and exit.
* `--direct`: Do not perform post-processing; use
original image.
Post-Processing Options
-----------------------
* `--simplify INT`: Before morphology analysis, reduce
image dimensions by this factor
(default: 2).
@ -148,6 +154,7 @@ EOF
##
# Arguments
direct=false
i=1
options_done=false
@ -160,6 +167,11 @@ while [[ $i -le $# ]] ; do
print_help
exit 0
;;
--direct)
direct=true
i=$((i+1))
continue
;;
--simplify| \
--morphology| \
--morphology-shape| \
@ -262,7 +274,15 @@ if [[ $rv -ne 0 ]] ; then
error "One or more errors during input file naming; aborted." "$rv"
fi
for jpg in "$indir/"*.jpg ; do
if "$direct" ; then
for jpg in "$indir/"*.jpg ; do
base=$(basename "$jpg" .jpg)
out="$outdir/$base.png"
info "Resizing $jpg to $out ..."
convert -resize 1024 -dither Riemersma -colors 24 "$jpg" "$out"
done
else
for jpg in "$indir/"*.jpg ; do
base=$(basename "$jpg" .jpg)
tmp1="$tmpdir/$base.tmp1.png"
tmp2="$tmpdir/$base.tmp2.png"
@ -372,7 +392,8 @@ for jpg in "$indir/"*.jpg ; do
rv=1
continue
fi
done
done
fi # !direct
if [[ $rv -ne 0 ]] ; then
error "One or more errors during image conversion; aborted." "$rv"
@ -437,13 +458,15 @@ while read -r pdf ; do
input+=("$pdf")
done < <(ls -- "$tmpdir/"*.backdropped.pdf)
result_pdf=$(readlink -f "$result_filename")
if ! \
qpdf \
--empty \
--pages "${input[@]}" \
-- "$result_filename"
-- "$result_pdf"
then
warning "Could not concatenate \"$result_filename\"."
warning "Could not concatenate \"$result_pdf\"."
rv=1
elif ! "$keep_tmpfiles" ; then
if ! rm -f -- "$tmp_base" ; then