#!/bin/sh # Regenerate alkane-toolkit.icns (the macOS app icon) from the in-repo # microchip glyph: the same white chip on a rounded amber tile as the Windows # icon, at the sizes macOS asks for (16-1024 px). Needs rsvg-convert, # ImageMagick and python3; the .icns is committed, so a build never runs this. set -e cd "$(dirname "$0")" GLYPH=../assets/icons/microchip-solid-full.svg TMP=$(mktemp -d) trap 'rm -rf "$TMP"' 0 sed 's/currentColor/#ffffff/g; s/ "$TMP/glyph.svg" for s in 16 32 64 128 256 512 1024; do # Apple's grid: the tile fills ~80% of the canvas, centred. t=$((s * 80 / 100)); m=$(((s - t) / 2)); r=$((t * 22 / 100)) g=$((t * 60 / 100)); o=$(((s - g) / 2)) rsvg-convert -w "$g" -h "$g" "$TMP/glyph.svg" -o "$TMP/g$s.png" convert -size "${s}x${s}" xc:none -fill '#d9822b' \ -draw "roundrectangle $m,$m $((m + t - 1)),$((m + t - 1)) $r,$r" \ "$TMP/g$s.png" -geometry "+$o+$o" -composite "PNG32:$TMP/i$s.png" done python3 - "$TMP" alkane-toolkit.icns <<'PY' import pathlib, struct, sys tmp, out = pathlib.Path(sys.argv[1]), sys.argv[2] # ICNS element types that hold PNG data, by pixel size. types = [("icp4", 16), ("icp5", 32), ("icp6", 64), ("ic07", 128), ("ic08", 256), ("ic09", 512), ("ic10", 1024), ("ic11", 32), ("ic12", 64), ("ic13", 256), ("ic14", 512)] body = b"" for kind, size in types: data = (tmp / f"i{size}.png").read_bytes() body += kind.encode() + struct.pack(">I", len(data) + 8) + data pathlib.Path(out).write_bytes(b"icns" + struct.pack(">I", len(body) + 8) + body) PY echo "wrote $(pwd)/alkane-toolkit.icns"