Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Meta: Add a PNG size check to CI and pre-commit checks

This uses optipng to check how much size can be reduced on PNG files. If
that's more than 2 KiB for at least one file, the check fails. As with
other checks, it doesn't run if optipng is not installed.

authored by

kleines Filmröllchen and committed by
Ali Mohammad Pur
2c6e3ea2 bae330d5

+43
+42
Meta/check-png-sizes.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + set -eo pipefail 4 + 5 + # How many bytes optipng has to be able to strip out of the file for the optimization to be worth it. The default is 1 KiB. 6 + : "${MINIMUM_OPTIMIZATION_BYTES:=1024}" 7 + 8 + script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P) 9 + cd "${script_path}/.." 10 + 11 + if ! command -v optipng >/dev/null ; then 12 + echo 'optipng is not installed, skipping png size check.' 13 + echo 'Please install optipng for your system to run this check.' 14 + exit 0 15 + fi 16 + 17 + files=() 18 + for file in "$@"; do 19 + if [[ "${file}" == *".png" ]]; then 20 + files+=("${file}") 21 + fi 22 + done 23 + 24 + if (( ${#files[@]} )); then 25 + # We need to allow optipng to write output so we can check what it actually did. We use a dummy file that's discarded afterwards. 26 + optimizations=$( printf '%s\0' "${files[@]}" |\ 27 + xargs -0 -n1 optipng -strip all -out dummy-optipng-output.png -clobber 2>&1 |\ 28 + grep -i -e 'Output IDAT size =' |\ 29 + sed -E 's/Output IDAT size = [0-9]+ byte(s?) \(([0-9]+) byte(s?) decrease\)/\2/g;s/Output IDAT size = [0-9]+ byte(s?) \(no change\)/0/g' |\ 30 + awk "{ if (\$1 >= $MINIMUM_OPTIMIZATION_BYTES) { S+=\$1 } } END { print S }") 31 + rm -f dummy-optipng-output.png dummy-optipng-output.png.bak 32 + optimizations="${optimizations:-0}" 33 + 34 + if [[ "$optimizations" -ne 0 ]] ; then 35 + echo "There are non-optimized PNG images in Base/. It is possible to reduce file sizes by at least $optimizations byte(s)." 36 + # shellcheck disable=SC2016 # we're not trying to expand expressions here 37 + echo 'Please run optipng with `-strip all` on modified PNG images and try again.' 38 + exit 1 39 + fi 40 + else 41 + echo 'No PNG images to check.' 42 + fi
+1
Meta/lint-ci.sh
··· 24 24 Meta/check-debug-flags.sh \ 25 25 Meta/check-markdown.sh \ 26 26 Meta/check-newlines-at-eof.py \ 27 + Meta/check-png-sizes.sh \ 27 28 Meta/check-style.py \ 28 29 Meta/lint-executable-resources.sh \ 29 30 Meta/lint-keymaps.py \