From 5541b73e2009e0e08b483d3959ae273d30e2d221 Mon Sep 17 00:00:00 2001 From: William Floyd Date: Wed, 27 May 2020 18:10:57 -0400 Subject: [PATCH] images_build: Check for some programs on start, make JPEG operations generic. --- src/images_build.sh | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/images_build.sh b/src/images_build.sh index 4905756..7e94a83 100755 --- a/src/images_build.sh +++ b/src/images_build.sh @@ -1,6 +1,23 @@ #!/bin/bash -[ "$(env | /bin/sed -r -e '/^(PWD|SHLVL|_)=/d')" ] && exec -c $0 +############################################################################### + +[ "$(env | /bin/sed -r -e '/^(PWD|SHLVL|_|PATH)=/d')" ] && exec -c $0 + +export PATH + +############################################################################### + +__needed_programs='convert +jpegoptim +fdp +zopflipng' + +while read -r __program; do + if ! which "${__program}" &>/dev/null; then + echo "Error: Need '${__program}'" + fi +done <<<"${__needed_programs}" ############################################################################### # Variables @@ -9,7 +26,8 @@ __ignore_variables='PWD SHLVL _ -OLDPWD' +OLDPWD +PATH' ######################################## # Default Options @@ -245,14 +263,18 @@ __process_generic_image() { rm "${__target}" fi - if [ "${__JPEG_RESCALE}" == 'true' ]; then - convert "${__source_file}" -quality "${JPEG_QUALITY}" -auto-orient -resize "${JPEG_SCALE}"% "${__target}" + __img_rescale="__${1^^}_RESCALE" + + if [ "${!__img_rescale}" == 'true' ]; then + "__rescale_${1}" "${__source_file}" "${__target}" else cp "${__source_file}" "${__target}" fi - if [ "${__JPEG_OPTIMIZE}" == 'true' ]; then - jpegoptim -s "${__target}" 1>/dev/null + __img_optimize="__${1^^}_OPTIMIZE" + + if [ "${!__img_optimize}" == 'true' ]; then + "__optimize_${1}" "${__target}" fi fi @@ -265,6 +287,14 @@ __process_generic_image() { } +__rescale_jpeg() { + convert "${1}" -quality "${JPEG_QUALITY}" -auto-orient -resize "${JPEG_SCALE}"% "${2}" +} + +__optimize_jpeg() { + jpegoptim -s "${1}" 1>/dev/null +} + ######################################## # __get_hash_file ########################################