|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Generate ICNS file from a source PNG |
| 4 | +# Usage: bash scripts/generate-icns.sh [source.png] [output.icns] |
| 5 | +# Defaults: source=build/[email protected], output=build/app-icon.icns |
| 6 | + |
| 7 | +set -e |
| 8 | + |
| 9 | +SOURCE_PNG="${1:-build/icon@3x.png}" |
| 10 | +OUTPUT_ICNS="${2:-build/app-icon.icns}" |
| 11 | +ICONSET_DIR=$(mktemp -d)/icon.iconset |
| 12 | + |
| 13 | +if [ ! -f "$SOURCE_PNG" ]; then |
| 14 | + echo "Error: Source PNG not found: $SOURCE_PNG" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +echo "Creating iconset from $SOURCE_PNG..." |
| 19 | + |
| 20 | +mkdir -p "$ICONSET_DIR" |
| 21 | + |
| 22 | +# Scale factor for macOS icon guidelines: 832/1024 = 13/16 = 0.8125 |
| 23 | +# This gives proper padding matching native macOS icons |
| 24 | +SCALE=0.8125 |
| 25 | + |
| 26 | +# Generate all required icon sizes with padding |
| 27 | +sips -z 16 16 "$SOURCE_PNG" --out "$ICONSET_DIR/icon_16x16.png" > /dev/null |
| 28 | +sips -Z $(echo "16 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/icon_16x16.png" --padToHeightWidth 16 16 > /dev/null |
| 29 | + |
| 30 | +sips -z 32 32 "$SOURCE_PNG" --out "$ICONSET_DIR/[email protected]" > /dev/null |
| 31 | +sips -Z $(echo "32 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/[email protected]" --padToHeightWidth 32 32 > /dev/null |
| 32 | + |
| 33 | +sips -z 32 32 "$SOURCE_PNG" --out "$ICONSET_DIR/icon_32x32.png" > /dev/null |
| 34 | +sips -Z $(echo "32 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/icon_32x32.png" --padToHeightWidth 32 32 > /dev/null |
| 35 | + |
| 36 | +sips -z 64 64 "$SOURCE_PNG" --out "$ICONSET_DIR/[email protected]" > /dev/null |
| 37 | +sips -Z $(echo "64 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/[email protected]" --padToHeightWidth 64 64 > /dev/null |
| 38 | + |
| 39 | +sips -z 128 128 "$SOURCE_PNG" --out "$ICONSET_DIR/icon_128x128.png" > /dev/null |
| 40 | +sips -Z $(echo "128 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/icon_128x128.png" --padToHeightWidth 128 128 > /dev/null |
| 41 | + |
| 42 | +sips -z 256 256 "$SOURCE_PNG" --out "$ICONSET_DIR/[email protected]" > /dev/null |
| 43 | +sips -Z $(echo "256 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/[email protected]" --padToHeightWidth 256 256 > /dev/null |
| 44 | + |
| 45 | +sips -z 256 256 "$SOURCE_PNG" --out "$ICONSET_DIR/icon_256x256.png" > /dev/null |
| 46 | +sips -Z $(echo "256 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/icon_256x256.png" --padToHeightWidth 256 256 > /dev/null |
| 47 | + |
| 48 | +sips -z 512 512 "$SOURCE_PNG" --out "$ICONSET_DIR/[email protected]" > /dev/null |
| 49 | +sips -Z $(echo "512 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/[email protected]" --padToHeightWidth 512 512 > /dev/null |
| 50 | + |
| 51 | +sips -z 512 512 "$SOURCE_PNG" --out "$ICONSET_DIR/icon_512x512.png" > /dev/null |
| 52 | +sips -Z $(echo "512 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/icon_512x512.png" --padToHeightWidth 512 512 > /dev/null |
| 53 | + |
| 54 | +sips -z 1024 1024 "$SOURCE_PNG" --out "$ICONSET_DIR/[email protected]" > /dev/null |
| 55 | +sips -Z $(echo "1024 * $SCALE" | bc | cut -d. -f1) "$ICONSET_DIR/[email protected]" --padToHeightWidth 1024 1024 > /dev/null |
| 56 | + |
| 57 | +echo "Converting iconset to ICNS..." |
| 58 | + |
| 59 | +# Convert iconset to icns |
| 60 | +iconutil -c icns "$ICONSET_DIR" -o "$OUTPUT_ICNS" |
| 61 | + |
| 62 | +# Clean up |
| 63 | +rm -rf "$(dirname "$ICONSET_DIR")" |
| 64 | + |
| 65 | +echo "✓ Created $OUTPUT_ICNS" |
0 commit comments