this repo has no description
at main 49 lines 1.5 kB view raw
1#!/usr/bin/env bash 2set -euo pipefail 3 4ICON_FILE=${1:-Icon.icon} 5BASENAME=${2:-Icon} 6OUT_ROOT=${3:-build/icon} 7XCODE_APP=${XCODE_APP:-/Applications/Xcode.app} 8 9ICTOOL="$XCODE_APP/Contents/Applications/Icon Composer.app/Contents/Executables/ictool" 10if [[ ! -x "$ICTOOL" ]]; then 11 ICTOOL="$XCODE_APP/Contents/Applications/Icon Composer.app/Contents/Executables/icontool" 12fi 13if [[ ! -x "$ICTOOL" ]]; then 14 echo "ictool/icontool not found. Set XCODE_APP if Xcode is elsewhere." >&2 15 exit 1 16fi 17 18ICONSET_DIR="$OUT_ROOT/${BASENAME}.iconset" 19TMP_DIR="$OUT_ROOT/tmp" 20mkdir -p "$ICONSET_DIR" "$TMP_DIR" 21 22MASTER_ART="$TMP_DIR/icon_art_824.png" 23MASTER_1024="$TMP_DIR/icon_1024.png" 24 25# Render inner art (no margin) with macOS Default appearance 26"$ICTOOL" "$ICON_FILE" \ 27 --export-preview macOS Default 824 824 1 -45 "$MASTER_ART" 28 29# Pad to 1024x1024 with transparent border 30sips --padToHeightWidth 1024 1024 "$MASTER_ART" --out "$MASTER_1024" >/dev/null 31 32# Generate required sizes 33sizes=(16 32 64 128 256 512 1024) 34for sz in "${sizes[@]}"; do 35 out="$ICONSET_DIR/icon_${sz}x${sz}.png" 36 sips -z "$sz" "$sz" "$MASTER_1024" --out "$out" >/dev/null 37 if [[ "$sz" -ne 1024 ]]; then 38 dbl=$((sz*2)) 39 out2="$ICONSET_DIR/icon_${sz}x${sz}@2x.png" 40 sips -z "$dbl" "$dbl" "$MASTER_1024" --out "$out2" >/dev/null 41 fi 42done 43 44# 512x512@2x already covered by 1024; ensure it exists 45cp "$MASTER_1024" "$ICONSET_DIR/icon_512x512@2x.png" 46 47iconutil -c icns "$ICONSET_DIR" -o Icon.icns 48 49echo "Icon.icns generated at $(pwd)/Icon.icns"