summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik Jäger <gitcommit@henk.geekmail.org>2022-12-29 10:36:31 +0100
committerHendrik Jäger <gitcommit@henk.geekmail.org>2022-12-29 10:36:31 +0100
commit0b844ff0879674034d6a2c0457191fa6e4513b61 (patch)
tree7f666abdcdbf81084e9cd05deefc7c5500fb7e0d
parenta96a9b0113336a584286c18131ffa5a934a6561f (diff)
refactor and handle errors
-rw-r--r--.zsh_functions/henkspngpostproc41
1 files changed, 23 insertions, 18 deletions
diff --git a/.zsh_functions/henkspngpostproc b/.zsh_functions/henkspngpostproc
index c35650d..e721f4c 100644
--- a/.zsh_functions/henkspngpostproc
+++ b/.zsh_functions/henkspngpostproc
@@ -1,25 +1,30 @@
+setopt PIPE_FAIL
+
local resize_by
local img
resize_by="$1"
shift
-echo "Creating Directories …"
-mkdir --parents resized/pngnqed/optipnged optimized
for img in $*
do
- echo "Resizing image …"
- convert -resize $resize_by% "$img" "resized/$img"
- echo "Running pngnq …"
- pngnq -s1 -f -d "resized/pngnqed" -e .png "resized/$img"
- echo "Running optipng …"
- optipng -force -out "resized/pngnqed/optipnged/$img" "resized/pngnqed/$img"
- echo "Moving final image to directory 'optimized' …"
- cp --verbose --interactive --target-directory=optimized/ "resized/pngnqed/optipnged/$img"
- echo "Removing temporary images …"
- #rm --verbose --interactive \
- rm --verbose \
- "resized/$img" \
- "resized/pngnqed/$img" \
- "resized/pngnqed/optipnged/$img"
- img2pdf --output $(basename $img .png).pdf optimized/${img}
+ echo "Processing ${img} ..."
+ # mostly to remove the alpha channel so ocrmypdf can work with it
+ # does not seem to work all the time, so 'convert' is used as well below
+ # still nice to optimize
+ optipng "${img}"
+ if [ $? -ne 0 ]
+ then
+ echo "optipng failed"
+ return
+ fi
+ # resize
+ # and remove alpha channel so ocrmypdf can work with it
+ # ocrmypdf does the quantization of the png which reduces size drastically
+ convert -resize $resize_by% -alpha off "$img" - \
+ | ocrmypdf - "$(basename $img .png).pdf"
+ if [ $? -ne 0 ]
+ then
+ echo "convert or ocrmypdf failed"
+ return
+ fi
done
-rmdir --parents resized/pngnqed/optipnged
+