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

@ -19,15 +19,17 @@ loop_1() {
nice -n 10 oxipng -o max "${p}" #&> /dev/null
elif [[ "${p}" =~ Web/P ]]; 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 -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
fi
fi
fi
fi

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

View file

@ -37,15 +37,17 @@ wait
#compress-webp
while read -r s; do
#If file is not animated
if ! grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp #&>/dev/null
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [[ -n "${size_original}" && -n "${size_new}" && "${size_original}" -gt "${size_new}" ]]; then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else
rm /tmp/"${s##.*\/}"_temp.webp
if [[ -f "${s}" ]]; then
if grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp #&>/dev/null
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [[ -n "${size_original}" && -n "${size_new}" && "${size_original}" -gt "${size_new}" ]]; then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else
rm /tmp/"${s##.*\/}"_temp.webp
fi
fi
fi
fi
@ -76,15 +78,17 @@ while read -r j; do
elif file -b "${j}" | grep -q "Web/P"; then
mv "${j}" "${j%.*}".webp
#If file is not animated
if ! grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp #&>/dev/null
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [[ -n "${size_original}" && -n "${size_new}" && "${size_original}" -gt "${size_new}" ]]; then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else
rm /tmp/"${s##.*\/}"_temp.webp
if [[ -f "${j}" ]]; then
if grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp #&>/dev/null
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [[ -n "${size_original}" && -n "${size_new}" && "${size_original}" -gt "${size_new}" ]]; then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else
rm /tmp/"${s##.*\/}"_temp.webp
fi
fi
fi
fi
@ -102,15 +106,17 @@ while read -r k; do
elif file -b "${k}" | grep -q "Web/P"; then
mv "${k}" "${k%.*}".webp
#If file is not animated
if ! grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp #&>/dev/null
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [[ -n "${size_original}" && -n "${size_new}" && "${size_original}" -gt "${size_new}" ]]; then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else
rm /tmp/"${s##.*\/}"_temp.webp
if [[ -f "${k}" ]]; then
if grep -v -q -e "ANIM" -e "ANMF" "${s}"; then
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp #&>/dev/null
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]; then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [[ -n "${size_original}" && -n "${size_new}" && "${size_original}" -gt "${size_new}" ]]; then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
else
rm /tmp/"${s##.*\/}"_temp.webp
fi
fi
fi
fi