116 lines
3.5 KiB
Bash
Executable file
116 lines
3.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$repo_root"
|
|
|
|
ictool="/Applications/Xcode/Xcode.app/Contents/Applications/Icon Composer.app/Contents/Executables/ictool"
|
|
icon_doc="$repo_root/design/brand/Burrow.icon"
|
|
output_dir_arg="${1:-design/brand/low-res}"
|
|
if [[ "$output_dir_arg" = /* ]]; then
|
|
output_dir="$output_dir_arg"
|
|
else
|
|
output_dir="$repo_root/$output_dir_arg"
|
|
fi
|
|
master="$output_dir/burrow-icon-1024.png"
|
|
checked_in_master="$repo_root/design/brand/burrow-owl-icon-master.png"
|
|
source_master="$checked_in_master"
|
|
sizes=(16 20 24 29 32 40 48 64 80 128 256)
|
|
|
|
require_tool() {
|
|
if ! command -v "$1" >/dev/null 2>&1; then
|
|
echo "error: required tool not found: $1" >&2
|
|
exit 127
|
|
fi
|
|
}
|
|
|
|
require_tool magick
|
|
require_tool awk
|
|
|
|
if [[ ! -x "$ictool" ]]; then
|
|
echo "error: Icon Composer ictool not found at $ictool" >&2
|
|
exit 127
|
|
fi
|
|
|
|
mkdir -p "$output_dir"
|
|
|
|
if [[ "${BURROW_ICON_REFRESH:-0}" == "1" ]]; then
|
|
if ! "$ictool" "$icon_doc" \
|
|
--export-image \
|
|
--output-file "$master" \
|
|
--platform iOS \
|
|
--rendition Default \
|
|
--width 1024 \
|
|
--height 1024 \
|
|
--scale 1 >/dev/null; then
|
|
echo "warning: ictool could not export $icon_doc; falling back to $checked_in_master" >&2
|
|
magick "$checked_in_master" -colorspace sRGB -strip "PNG24:$master"
|
|
source_master="$checked_in_master"
|
|
else
|
|
source_master="$master"
|
|
fi
|
|
else
|
|
magick "$checked_in_master" -colorspace sRGB -strip "PNG24:$master"
|
|
fi
|
|
|
|
printf "size,colors,gray_stddev,status\n" >"$output_dir/report.csv"
|
|
|
|
for size in "${sizes[@]}"; do
|
|
image="$output_dir/burrow-icon-${size}.png"
|
|
magick "$source_master" -colorspace sRGB -resize "${size}x${size}!" -strip "PNG24:$image"
|
|
|
|
actual="$(magick "$image" -format "%wx%h" info:)"
|
|
if [[ "$actual" != "${size}x${size}" ]]; then
|
|
echo "error: $image rendered as $actual, expected ${size}x${size}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
colors="$(magick "$image" -format "%k" info:)"
|
|
stddev="$(magick "$image" -colorspace Gray -format "%[fx:standard_deviation]" info:)"
|
|
min_colors=$((size * 4))
|
|
if (( min_colors < 48 )); then
|
|
min_colors=48
|
|
fi
|
|
if (( min_colors > 900 )); then
|
|
min_colors=900
|
|
fi
|
|
|
|
awk -v size="$size" -v colors="$colors" -v min_colors="$min_colors" -v stddev="$stddev" '
|
|
BEGIN {
|
|
if (colors < min_colors) {
|
|
printf "error: %dpx icon has only %d colors; expected at least %d\n", size, colors, min_colors > "/dev/stderr";
|
|
exit 1;
|
|
}
|
|
if (stddev < 0.08) {
|
|
printf "error: %dpx icon grayscale stddev is %.6f; expected at least 0.08\n", size, stddev > "/dev/stderr";
|
|
exit 1;
|
|
}
|
|
}
|
|
'
|
|
|
|
printf "%s,%s,%s,ok\n" "$size" "$colors" "$stddev" >>"$output_dir/report.csv"
|
|
done
|
|
|
|
preview_inputs=()
|
|
pixel_preview_inputs=()
|
|
for size in 256 128 80 64 48 40 32 29 24 20 16; do
|
|
preview="$output_dir/preview-${size}.png"
|
|
if (( size <= 32 )); then
|
|
filter=Point
|
|
else
|
|
filter=Lanczos
|
|
fi
|
|
magick "$output_dir/burrow-icon-${size}.png" -filter "$filter" -resize 128x128 "$preview"
|
|
preview_inputs+=("$preview")
|
|
|
|
if (( size <= 32 )); then
|
|
pixel_preview="$output_dir/pixel-preview-${size}.png"
|
|
magick "$output_dir/burrow-icon-${size}.png" -filter Point -resize 128x128 "$pixel_preview"
|
|
pixel_preview_inputs+=("$pixel_preview")
|
|
fi
|
|
done
|
|
|
|
magick -background "#202020" -gravity center "${preview_inputs[@]}" +append "$output_dir/preview-strip.png"
|
|
magick -background "#202020" -gravity center "${pixel_preview_inputs[@]}" +append "$output_dir/pixel-preview-strip.png"
|
|
|
|
echo "low-res icon exports written to $output_dir"
|