111 lines
4.2 KiB
Bash
Executable File
111 lines
4.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
SVG="$ROOT/assets/Icon.svg"
|
|
ASSETS="$ROOT/ios/Assets.xcassets"
|
|
APPICON="$ASSETS/AppIcon.appiconset"
|
|
|
|
if [ ! -f "$SVG" ]; then
|
|
echo "ERROR: $SVG not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v rsvg-convert >/dev/null 2>&1; then
|
|
echo "ERROR: rsvg-convert not on PATH (brew install librsvg)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
rm -rf "$APPICON"
|
|
mkdir -p "$APPICON"
|
|
|
|
WORK_SVG="$(mktemp -t icon-svg.XXXXXX)"
|
|
trap 'rm -f "$WORK_SVG"' EXIT
|
|
|
|
# pulls the gradient labeled #bg-color and paints it across the whole viewBox under the existing artwork.
|
|
BG_FLAG=()
|
|
if grep -q 'id="bg-color"' "$SVG"; then
|
|
VIEWBOX="$(grep -oE 'viewBox="[^"]+"' "$SVG" | head -1 | sed -E 's/viewBox="//;s/"$//')"
|
|
read -r VBX VBY VBW VBH <<<"$VIEWBOX"
|
|
INJECT="<rect x=\"${VBX}\" y=\"${VBY}\" width=\"${VBW}\" height=\"${VBH}\" fill=\"url(#bg-color)\"/>"
|
|
awk -v inj="$INJECT" '/<\/defs>/ {print; print inj; next} {print}' "$SVG" > "$WORK_SVG"
|
|
echo "Injected #bg-color full-canvas fill"
|
|
else
|
|
cp "$SVG" "$WORK_SVG"
|
|
BG_FLAG=(--background-color="${YRXTALS_ICON_BG:-black}")
|
|
echo "No #bg-color id; falling back to solid ${YRXTALS_ICON_BG:-black}"
|
|
fi
|
|
|
|
SIZES=(
|
|
"Icon-20.png 20"
|
|
"Icon-20@2x.png 40"
|
|
"Icon-20@3x.png 60"
|
|
"Icon-29.png 29"
|
|
"Icon-29@2x.png 58"
|
|
"Icon-29@3x.png 87"
|
|
"Icon-40.png 40"
|
|
"Icon-40@2x.png 80"
|
|
"Icon-40@3x.png 120"
|
|
"Icon-60@2x.png 120"
|
|
"Icon-60@3x.png 180"
|
|
"Icon-76.png 76"
|
|
"Icon-76@2x.png 152"
|
|
"Icon-83.5@2x.png 167"
|
|
"Icon-1024.png 1024"
|
|
)
|
|
|
|
for entry in "${SIZES[@]}"; do
|
|
name="${entry%% *}"
|
|
size="${entry##* }"
|
|
rsvg-convert "${BG_FLAG[@]}" --width="$size" --height="$size" "$WORK_SVG" -o "$APPICON/$name"
|
|
done
|
|
|
|
# strips the alpha channel from the 1024 marketing icon for App Store validation.
|
|
if command -v magick >/dev/null 2>&1; then
|
|
magick "$APPICON/Icon-1024.png" -alpha remove -alpha off "$APPICON/Icon-1024.png"
|
|
elif command -v convert >/dev/null 2>&1; then
|
|
convert "$APPICON/Icon-1024.png" -alpha remove -alpha off "$APPICON/Icon-1024.png"
|
|
else
|
|
echo "WARNING: ImageMagick not on PATH; the 1024 icon still has an alpha channel. brew install imagemagick" >&2
|
|
fi
|
|
|
|
cat > "$ASSETS/Contents.json" <<'EOF'
|
|
{
|
|
"info" : {
|
|
"author" : "xcode",
|
|
"version" : 1
|
|
}
|
|
}
|
|
EOF
|
|
|
|
cat > "$APPICON/Contents.json" <<'EOF'
|
|
{
|
|
"images" : [
|
|
{ "idiom" : "iphone", "size" : "20x20", "scale" : "2x", "filename" : "Icon-20@2x.png" },
|
|
{ "idiom" : "iphone", "size" : "20x20", "scale" : "3x", "filename" : "Icon-20@3x.png" },
|
|
{ "idiom" : "iphone", "size" : "29x29", "scale" : "2x", "filename" : "Icon-29@2x.png" },
|
|
{ "idiom" : "iphone", "size" : "29x29", "scale" : "3x", "filename" : "Icon-29@3x.png" },
|
|
{ "idiom" : "iphone", "size" : "40x40", "scale" : "2x", "filename" : "Icon-40@2x.png" },
|
|
{ "idiom" : "iphone", "size" : "40x40", "scale" : "3x", "filename" : "Icon-40@3x.png" },
|
|
{ "idiom" : "iphone", "size" : "60x60", "scale" : "2x", "filename" : "Icon-60@2x.png" },
|
|
{ "idiom" : "iphone", "size" : "60x60", "scale" : "3x", "filename" : "Icon-60@3x.png" },
|
|
{ "idiom" : "ipad", "size" : "20x20", "scale" : "1x", "filename" : "Icon-20.png" },
|
|
{ "idiom" : "ipad", "size" : "20x20", "scale" : "2x", "filename" : "Icon-20@2x.png" },
|
|
{ "idiom" : "ipad", "size" : "29x29", "scale" : "1x", "filename" : "Icon-29.png" },
|
|
{ "idiom" : "ipad", "size" : "29x29", "scale" : "2x", "filename" : "Icon-29@2x.png" },
|
|
{ "idiom" : "ipad", "size" : "40x40", "scale" : "1x", "filename" : "Icon-40.png" },
|
|
{ "idiom" : "ipad", "size" : "40x40", "scale" : "2x", "filename" : "Icon-40@2x.png" },
|
|
{ "idiom" : "ipad", "size" : "76x76", "scale" : "1x", "filename" : "Icon-76.png" },
|
|
{ "idiom" : "ipad", "size" : "76x76", "scale" : "2x", "filename" : "Icon-76@2x.png" },
|
|
{ "idiom" : "ipad", "size" : "83.5x83.5","scale" : "2x","filename" : "Icon-83.5@2x.png" },
|
|
{ "idiom" : "ios-marketing","size" : "1024x1024","scale" : "1x","filename" : "Icon-1024.png" }
|
|
],
|
|
"info" : {
|
|
"author" : "xcode",
|
|
"version" : 1
|
|
}
|
|
}
|
|
EOF
|
|
|
|
echo "Wrote $APPICON ($(ls "$APPICON" | wc -l | tr -d ' ') files)"
|