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
elif [[ "${p}" =~ .webp ]]
then
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
if [[ -f /tmp/temp.webp ]]
#If file is not animated
if [[ $(grep -v -q -e "ANIM" -e "ANMF" "${p}" ]]
then
size_new=$(stat -c%s "/tmp/temp.webp" || 0 )
size_original=$(stat -c%s "${p}")
if [[ "${size_original}" -gt "${size_new}" ]]
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
if [[ -f /tmp/temp.webp ]]
then
mv /tmp/temp.webp "${p}" #&> /dev/null
else
rm /tmp/temp.webp #&> /dev/null
size_new=$(stat -c%s "/tmp/temp.webp" || 0 )
size_original=$(stat -c%s "${p}")
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