86 lines
2.9 KiB
Bash
Executable file
86 lines
2.9 KiB
Bash
Executable file
#!/bin/bash
|
|
# Konvertiert das Pageta-SVG-Icon (Source: pageta-web) zu PNG @1024
|
|
# für den Asset-Catalog.
|
|
#
|
|
# Erstellt von π-0 Brand-Refresh 2026-05-18. Source ist
|
|
# /Users/till/Developer/pageta/apps/web/static/icon-512.svg (oder
|
|
# der pageta.com-prod-Pfad via curl).
|
|
#
|
|
# Tool-Reihenfolge: rsvg-convert (Homebrew librsvg) → qlmanage (macOS
|
|
# built-in, etwas weniger sauber, aber fallback). Wenn beide fehlen,
|
|
# Fehler mit Install-Hinweis.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
ICON_DIR="$REPO_ROOT/Sources/Resources/Assets.xcassets/AppIcon.appiconset"
|
|
ICON_1024="$ICON_DIR/pageta-icon-1024.png"
|
|
ICON_512="$ICON_DIR/pageta-icon-512.png"
|
|
|
|
# Source: Schwester-Repo bevorzugt (Dev-Zyklus), sonst Prod-URL als
|
|
# Fallback (fresh-clone-Szenario).
|
|
SVG_LOCAL="$REPO_ROOT/../pageta/apps/web/static/icon-512.svg"
|
|
SVG_URL="https://pageta.com/icon-512.svg"
|
|
|
|
TMP="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP"' EXIT
|
|
|
|
if [[ -f "$SVG_LOCAL" ]]; then
|
|
cp "$SVG_LOCAL" "$TMP/pageta-icon.svg"
|
|
echo "→ Source: $SVG_LOCAL"
|
|
else
|
|
echo "→ Source: $SVG_URL (local pageta repo not found)"
|
|
curl -sSf "$SVG_URL" -o "$TMP/pageta-icon.svg"
|
|
fi
|
|
|
|
if command -v rsvg-convert >/dev/null 2>&1; then
|
|
rsvg-convert -w 1024 -h 1024 "$TMP/pageta-icon.svg" -o "$ICON_1024"
|
|
rsvg-convert -w 512 -h 512 "$TMP/pageta-icon.svg" -o "$ICON_512"
|
|
echo "→ Tool: rsvg-convert"
|
|
elif command -v qlmanage >/dev/null 2>&1; then
|
|
qlmanage -t -s 1024 "$TMP/pageta-icon.svg" -o "$TMP" >/dev/null 2>&1
|
|
mv "$TMP/pageta-icon.svg.png" "$ICON_1024"
|
|
qlmanage -t -s 512 "$TMP/pageta-icon.svg" -o "$TMP" >/dev/null 2>&1
|
|
mv "$TMP/pageta-icon.svg.png" "$ICON_512"
|
|
echo "→ Tool: qlmanage (macOS QuickLook fallback)"
|
|
else
|
|
echo "✗ Brauche rsvg-convert oder qlmanage." >&2
|
|
echo " Install: brew install librsvg" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Alpha-Strip: Apple-ASC verwirft AppIcons mit Alpha-Kanal (ITMS-90717).
|
|
# Flatten auf den Pageta-Cream-Background (#f5efe6 = 245,239,230), damit
|
|
# der Background zur Page-Fläche im Icon passt. Pillow ist in macOS-Python
|
|
# meist verfügbar; ohne wird der Strip übersprungen (Warning, kein Fail —
|
|
# Build + Simulator stören sich nicht an Alpha, nur ASC-Submit).
|
|
flatten_alpha() {
|
|
local png="$1"
|
|
python3 - "$png" <<'PY' 2>/dev/null || return 1
|
|
import sys
|
|
from PIL import Image
|
|
path = sys.argv[1]
|
|
img = Image.open(path)
|
|
if img.mode != 'RGBA':
|
|
sys.exit(0)
|
|
bg = Image.new('RGB', img.size, (245, 239, 230))
|
|
bg.paste(img, mask=img.split()[3])
|
|
bg.save(path, 'PNG', optimize=True)
|
|
PY
|
|
}
|
|
|
|
if flatten_alpha "$ICON_1024" && flatten_alpha "$ICON_512"; then
|
|
echo "→ Alpha gestripped (Background #f5efe6 cream)"
|
|
else
|
|
echo "⚠ Pillow (python3 -m PIL) nicht verfügbar — PNGs behalten Alpha." >&2
|
|
echo " Vor ASC-Submit: brew install pillow oder pip install Pillow" >&2
|
|
fi
|
|
|
|
# Validierung
|
|
describe() {
|
|
local png="$1"
|
|
file "$png" | grep -oE '[0-9]+ x [0-9]+, [^,]+' | head -1
|
|
}
|
|
echo "✓ $ICON_1024 ($(describe "$ICON_1024"))"
|
|
echo "✓ $ICON_512 ($(describe "$ICON_512"))"
|