images_build: Check for some programs on start, make JPEG operations generic.
This commit is contained in:
parent
a08faeeb39
commit
5541b73e20
1 changed files with 36 additions and 6 deletions
|
|
@ -1,6 +1,23 @@
|
||||||
#!/bin/bash
|
#!/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
|
# Variables
|
||||||
|
|
@ -9,7 +26,8 @@
|
||||||
__ignore_variables='PWD
|
__ignore_variables='PWD
|
||||||
SHLVL
|
SHLVL
|
||||||
_
|
_
|
||||||
OLDPWD'
|
OLDPWD
|
||||||
|
PATH'
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
# Default Options
|
# Default Options
|
||||||
|
|
@ -245,14 +263,18 @@ __process_generic_image() {
|
||||||
rm "${__target}"
|
rm "${__target}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${__JPEG_RESCALE}" == 'true' ]; then
|
__img_rescale="__${1^^}_RESCALE"
|
||||||
convert "${__source_file}" -quality "${JPEG_QUALITY}" -auto-orient -resize "${JPEG_SCALE}"% "${__target}"
|
|
||||||
|
if [ "${!__img_rescale}" == 'true' ]; then
|
||||||
|
"__rescale_${1}" "${__source_file}" "${__target}"
|
||||||
else
|
else
|
||||||
cp "${__source_file}" "${__target}"
|
cp "${__source_file}" "${__target}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${__JPEG_OPTIMIZE}" == 'true' ]; then
|
__img_optimize="__${1^^}_OPTIMIZE"
|
||||||
jpegoptim -s "${__target}" 1>/dev/null
|
|
||||||
|
if [ "${!__img_optimize}" == 'true' ]; then
|
||||||
|
"__optimize_${1}" "${__target}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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 <file>
|
# __get_hash_file <file>
|
||||||
########################################
|
########################################
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue