fix: Add check for whether a WebP file is animated (cwebp does not support compressing animated files)

This commit is contained in:
Carlos Solís 2025-01-29 15:55:19 +00:00
parent badc0d824f
commit 164641f5f7

View file

@ -29,16 +29,20 @@ loop_1(){
nice -n 10 oxipng -o max "${p}" #&> /dev/null nice -n 10 oxipng -o max "${p}" #&> /dev/null
elif [[ "${p}" =~ .webp ]] elif [[ "${p}" =~ .webp ]]
then then
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null #If file is not animated
if [[ -f /tmp/temp.webp ]] if [[ $(grep -v -q -e "ANIM" -e "ANMF" "${p}" ]]
then then
size_new=$(stat -c%s "/tmp/temp.webp" || 0 ) nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
size_original=$(stat -c%s "${p}") if [[ -f /tmp/temp.webp ]]
if [[ "${size_original}" -gt "${size_new}" ]]
then then
mv /tmp/temp.webp "${p}" #&> /dev/null size_new=$(stat -c%s "/tmp/temp.webp" || 0 )
else size_original=$(stat -c%s "${p}")
rm /tmp/temp.webp #&> /dev/null if [[ "${size_original}" -gt "${size_new}" ]]
then
mv /tmp/temp.webp "${p}" #&> /dev/null
else
rm /tmp/temp.webp #&> /dev/null
fi
fi fi
fi fi
fi fi