Add script to optimize PNG textures using optipng

This commit is contained in:
Nils Dagsson Moskopp 2022-02-06 04:03:56 +01:00
parent 6abdbbbd13
commit 9d3cd2e7ef
No known key found for this signature in database
GPG Key ID: A3BC671C35191080
1 changed files with 27 additions and 0 deletions

27
tools/optimize-png-textures Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh
# Optimize all PNG textures using optipng, add them to Git index.
# Run this script from the root of the repository for the effect.
set -eu
LANG=C
PNG_FILES=$(find . -type f -name '*.png')
get_png_size_total() {
cat ${PNG_FILES} \
|wc -c
}
PNG_SIZE_TOTAL_BEFORE=$(get_png_size_total)
for PNG_FILE in ${PNG_FILES}; do
if git checkout "${PNG_FILE}"; then
printf '%s\n' "${PNG_FILE}"
optipng -o7 -zm1-9 -strip all "${PNG_FILE}"
git add "${PNG_FILE}"
fi
done
PNG_SIZE_TOTAL_AFTER=$(get_png_size_total)
printf 'PNG size total before:\t%s\n' "${PNG_SIZE_TOTAL_BEFORE}"
printf 'PNG size total after:\t%s\n' "${PNG_SIZE_TOTAL_AFTER}"