Mineclonia/tools/optimize-png-textures

28 lines
653 B
Bash
Executable File

#!/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}"