76 lines
1.6 KiB
Bash
76 lines
1.6 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
#set -u
|
|
#set -x
|
|
[ -n "$TERM" ] && clear
|
|
########################################################################
|
|
###
|
|
##
|
|
#
|
|
# Author: Stéphane HUC
|
|
# mail: devs@stephane-huc.net
|
|
# gpg:fingerprint: CE2C CF7C AB68 0329 0D20 5F49 6135 D440 4D44 BD58
|
|
#
|
|
# License: BSD License 2-Clause
|
|
#
|
|
# Git:
|
|
#
|
|
# Date: 2021/07/27
|
|
#
|
|
##
|
|
###
|
|
########################################################################
|
|
##
|
|
# Convert images to avif and webp formats
|
|
#
|
|
# ATTENTION: Generate new avif images is very slow!
|
|
#
|
|
##
|
|
########################################################################
|
|
###
|
|
#
|
|
# Need: libavif, libwebp
|
|
#
|
|
########################################################################
|
|
|
|
#ROOT="$(dirname "$(readlink -f -- "$0")")"
|
|
dir="/var/www/htdocs/pfstat/"
|
|
|
|
########################################################################
|
|
|
|
_avif() {
|
|
|
|
/usr/local/bin/avifenc -s 0 --min 25 --max 35 "${file}" "${file}.avif"
|
|
|
|
}
|
|
|
|
_webp() {
|
|
if [ -f "${file}.webp" ]; then rm -fP "${file}.webp"; fi
|
|
|
|
if [ ! -f "${file}.webp" ]; then
|
|
filetype="$(file -b "${file}")"
|
|
case "${filetype%% *}" in
|
|
'GIF')
|
|
/usr/local/bin/gif2webp -m 0 -mt "${file}" -o "${file}.webp"
|
|
;;
|
|
'JPEG'|'PNG'|'TIFF')
|
|
/usr/local/bin/cwebp -exact -lossless -m 0 -mt -progress "${file}" -o "${file}.webp"
|
|
;;
|
|
*)
|
|
printf '%s\n' "Format not supported!"
|
|
;;
|
|
esac
|
|
fi;
|
|
}
|
|
|
|
main() {
|
|
|
|
find "${dir}" -type f -a \( \
|
|
-name "*.gif" -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.tiff' \
|
|
\) | while read -r file; do _avif; _webp; done
|
|
}
|
|
|
|
########################################################################
|
|
|
|
main
|