image-build: Remove many image settings, use WEBP settings, correctly listen for script settings.
This commit is contained in:
parent
6c47ebba8a
commit
d93c18f324
1 changed files with 25 additions and 49 deletions
|
|
@ -10,10 +10,7 @@ export PATH
|
||||||
|
|
||||||
__needed_programs='convert
|
__needed_programs='convert
|
||||||
identify
|
identify
|
||||||
jpegoptim
|
|
||||||
img2webp
|
|
||||||
fdp
|
fdp
|
||||||
zopflipng
|
|
||||||
bc'
|
bc'
|
||||||
|
|
||||||
__fatal_error='false'
|
__fatal_error='false'
|
||||||
|
|
@ -39,49 +36,38 @@ PATH'
|
||||||
# Default Options
|
# Default Options
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
__global_scale='40'
|
|
||||||
|
|
||||||
__PROCESS_JPEG=true
|
__PROCESS_JPEG=true
|
||||||
__depends__PROCESS_JPEG=(JPEG_OPTIMIZE JPEG_RESCALE)
|
__depends__PROCESS_JPEG=(JPEG_RESCALE JPEG_CONVERT_LOSSLESS)
|
||||||
__JPEG_OPTIMIZE=true
|
# false/auto
|
||||||
# true/false/auto
|
|
||||||
__JPEG_RESCALE=auto
|
__JPEG_RESCALE=auto
|
||||||
__depends__JPEG_RESCALE=(JPEG_SCALE JPEG_QUALITY JPEG_RESCALE_THRESHOLD)
|
__depends__JPEG_RESCALE=(JPEG_RESCALE_THRESHOLD)
|
||||||
# for auto, in KP
|
# for auto, in KP
|
||||||
__JPEG_RESCALE_THRESHOLD=2000
|
__JPEG_RESCALE_THRESHOLD=2000
|
||||||
__JPEG_QUALITY=40
|
__JPEG_CONVERT_LOSSLESS=false
|
||||||
__JPEG_SCALE="${__global_scale}"
|
|
||||||
|
|
||||||
__PROCESS_PNG=true
|
__PROCESS_PNG=true
|
||||||
__depends__PROCESS_PNG=(PNG_OPTIMIZE PNG_RESCALE)
|
__depends__PROCESS_PNG=(PNG_RESCALE PNG_CONVERT_LOSSLESS)
|
||||||
__PNG_OPTIMIZE=true
|
# false/auto
|
||||||
__depends__PNG_OPTIMIZE=(PNG_EFFORT)
|
|
||||||
# quick/default/more/placebo
|
|
||||||
__PNG_EFFORT='default'
|
|
||||||
# true/false/auto
|
|
||||||
__PNG_RESCALE=auto
|
__PNG_RESCALE=auto
|
||||||
__depends__PNG_RESCALE=(PNG_SCALE PNG_QUALITY PNG_RESCALE_THRESHOLD)
|
__depends__PNG_RESCALE=(PNG_RESCALE_THRESHOLD)
|
||||||
# for auto, in KP
|
# for auto, in KP
|
||||||
__PNG_RESCALE_THRESHOLD=2000
|
__PNG_RESCALE_THRESHOLD=2000
|
||||||
__PNG_SCALE="${__global_scale}"
|
__PNG_CONVERT_LOSSLESS=true
|
||||||
__PNG_QUALITY=0
|
|
||||||
|
|
||||||
__PROCESS_SCRIPT=false
|
__PROCESS_SCRIPT=false
|
||||||
|
|
||||||
|
__WEBP_QUALITY='50'
|
||||||
|
|
||||||
__ENVIRONMENT_LIST='PROCESS_JPEG
|
__ENVIRONMENT_LIST='PROCESS_JPEG
|
||||||
PROCESS_PNG
|
PROCESS_PNG
|
||||||
PROCESS_SCRIPT
|
PROCESS_SCRIPT
|
||||||
JPEG_QUALITY
|
|
||||||
JPEG_RESCALE
|
JPEG_RESCALE
|
||||||
JPEG_RESCALE_THRESHOLD
|
JPEG_RESCALE_THRESHOLD
|
||||||
JPEG_SCALE
|
JPEG_CONVERT_LOSSLESS
|
||||||
JPEG_OPTIMIZE
|
|
||||||
PNG_OPTIMIZE
|
|
||||||
PNG_QUALITY
|
|
||||||
PNG_EFFORT
|
|
||||||
PNG_RESCALE
|
PNG_RESCALE
|
||||||
PNG_RESCALE_THRESHOLD
|
PNG_RESCALE_THRESHOLD
|
||||||
PNG_SCALE'
|
PNG_CONVERT_LOSSLESS
|
||||||
|
WEBP_QUALITY'
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Functions
|
# Functions
|
||||||
|
|
@ -252,14 +238,16 @@ __unset_unused() {
|
||||||
|
|
||||||
__process() {
|
__process() {
|
||||||
|
|
||||||
__process_scripts
|
if [ "${PROCESS_SCRIPT}" == 'true' ]; then
|
||||||
|
__process_scripts
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "${PROCESS_JPEG}" == 'true' ]; then
|
if [ "${PROCESS_JPEG}" == 'true' ]; then
|
||||||
__process_generic_image jpeg lossy
|
__process_generic_image jpeg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${PROCESS_PNG}" == 'true' ]; then
|
if [ "${PROCESS_PNG}" == 'true' ]; then
|
||||||
__process_generic_image png lossless
|
__process_generic_image png
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -274,7 +262,7 @@ __find_png() {
|
||||||
|
|
||||||
__process_generic_image() {
|
__process_generic_image() {
|
||||||
|
|
||||||
__mode="${2}"
|
__set_env './src/.env'
|
||||||
|
|
||||||
__unset_unused "${1}"
|
__unset_unused "${1}"
|
||||||
|
|
||||||
|
|
@ -300,26 +288,18 @@ __process_generic_image() {
|
||||||
|
|
||||||
__img_rescale="${1^^}_RESCALE"
|
__img_rescale="${1^^}_RESCALE"
|
||||||
__img_rescale_threshold="${1^^}_RESCALE_THRESHOLD"
|
__img_rescale_threshold="${1^^}_RESCALE_THRESHOLD"
|
||||||
|
__img_convert_lossless="${1^^}_CONVERT_LOSSLESS"
|
||||||
|
|
||||||
__print_env
|
__print_env
|
||||||
|
|
||||||
__convert_options=("-auto-orient" "-quality" "50")
|
__convert_options=("-auto-orient" "-quality" "${__WEBP_QUALITY}")
|
||||||
|
|
||||||
if [ "${__mode}" == 'lossless' ]; then
|
if [ "${!__img_convert_lossless}" == 'true' ]; then
|
||||||
__convert_options+=("-define" "webp:lossless=true")
|
__convert_options+=("-define" "webp:lossless=true")
|
||||||
else
|
|
||||||
__convert_options+=()
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (
|
if [ "${!__img_rescale}" == 'auto' ] && [ "$(identify -format '(%w*%h)/1000\n' "${__source_file}" | bc)" -gt "${!__img_rescale_threshold}" ]; then
|
||||||
[ "${!__img_rescale}" == 'true' ]
|
|
||||||
) ||
|
|
||||||
(
|
|
||||||
[ "${!__img_rescale}" == 'auto' ] && [ "$(identify -format '(%w*%h)/1000\n' "${__source_file}" | bc)" -gt "${!__img_rescale_threshold}" ]
|
|
||||||
); then
|
|
||||||
|
|
||||||
__convert_options+=("-resize" "$((__img_rescale_threshold * 1000))@>")
|
__convert_options+=("-resize" "$((__img_rescale_threshold * 1000))@>")
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
convert "${__source_file}" ${__convert_options[@]} "${__target}"
|
convert "${__source_file}" ${__convert_options[@]} "${__target}"
|
||||||
|
|
@ -330,8 +310,6 @@ __process_generic_image() {
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
__set_env './src/.env'
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__process_scripts() {
|
__process_scripts() {
|
||||||
|
|
@ -364,8 +342,6 @@ __process_scripts() {
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
__set_env './src/.env'
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
|
|
@ -402,7 +378,7 @@ __check_file() {
|
||||||
|
|
||||||
if [ "${#}" == '0' ]; then
|
if [ "${#}" == '0' ]; then
|
||||||
|
|
||||||
__targets="$(sed -e 's|^\./src/|./|' -e 's/[^\.]*$/webp/' <<<"${__source_file}")"
|
__targets="$(sed -e 's|^\./src/|./|' -e 's/\(jpeg\|jpg\|png\)$/webp/' <<<"${__source_file}")"
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
@ -444,7 +420,7 @@ __fatal_error_handler
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
pushd "$(dirname "$0")"
|
pushd "$(dirname "${0}")"
|
||||||
|
|
||||||
pushd ../
|
pushd ../
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue