fix: Rewrite to make more compliant

This commit is contained in:
Carlos Solís 2025-02-03 03:47:39 +00:00
parent 2ff422aaef
commit e7b88efe81

View file

@ -24,7 +24,18 @@ IFS="
done;
wait
)
find . -type f -iname "*.png" -size +300k | (
#Specific compression for large GIF files
find . -type f -iname "*.gif" -size +512000 | (
while read p
do
while [[ $(stat -c%s "${p}" || 0) -ge 512000 ]]
do
frameamount=$(exiftool -b -FrameCount "${p}")
nice -n 15 gifsicle "${p}" $(seq -f "#%g" 0 2 "${frameamount}") -O3 --lossy=80 --colors=255 -o "${p}"
done
done
)
find . -type f -iname "*.png" -size +500k | (
while read r
do
nice -n 15 oxipng -o max "${r}" &
@ -36,21 +47,25 @@ IFS="
wait
)
#compress-webp
find . -type f -iname "*.webp" -size +200k | (
find . -type f -iname "*.webp" -size +50k | (
while read s
do
nice -n 15 cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp
if [[ -f /tmp/"${s##.*\/}"_temp.webp ]]
#If file is not animated
if ! grep -v -q -e "ANIM" -e "ANMF" "${s}"
then
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp)
size_original=$(stat -c%s "${s}")
if [[ "${size_original}" -gt "${size_new}" ]]
cwebp -mt -af -quiet "${s}" -o /tmp/"${s##.*\/}"_temp.webp
if [ -f /tmp/"${s##.*\/}"_temp.webp ]
then
mv /tmp/"${s##.*\/}"_temp.webp "${s}"
size_new=$(stat -c%s /tmp/"${s##.*\/}"_temp.webp || 0)
size_original=$(stat -c%s "${s}" || 0)
if [ "$size_original" -gt "$size_new" ]
then
mv /tmp/"${s##.*\/}"_temp.webp "$s"
else
rm /tmp/"${s##.*\/}"_temp.webp
fi
fi
fi
done;
wait
)