fix: Improve the parsing of animated WebP files in case they're erased before testing

This commit is contained in:
Carlos Solís 2025-02-10 15:15:46 +00:00
parent 4414225297
commit 64442a97b3
3 changed files with 55 additions and 45 deletions

View file

@ -26,15 +26,17 @@ loop_1() {
nice -n 10 oxipng -o max "${p}" #&> /dev/null
elif [[ "${p}" =~ .webp ]]; then
#If file is not animated
if ! grep -v -q -e "ANIM" -e "ANMF" "${p}"; then
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
if [[ -f /tmp/temp.webp ]]; then
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
if [[ -f "${p}" ]]; then
if grep -q -v -e "ANIM" -e "ANMF" "${p}"; then
nice -n 10 cwebp -mt -af -quiet "${p}" -o /tmp/temp.webp #&> /dev/null
if [[ -f /tmp/temp.webp ]]; then
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