Files
life-echo/app-expo/scripts/generate-app-icon.sh
2026-03-23 10:25:51 +08:00

49 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 一次性:用 ImageMagick 7+magick从 assets/life-echo-logo.jpg 生成各平台 PNG。
# 依赖brew install imagemagick
# 用法:在 app-expo 目录执行 ./scripts/generate-app-icon.sh
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SRC="$ROOT/assets/life-echo-logo.jpg"
OUT="$ROOT/assets/images"
# 与 Android adaptiveIcon.backgroundColor、开屏底色一致新 logo 浅紫系)
BRAND_BG="#E6F4FE"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
if [[ ! -f "$SRC" ]]; then
echo "missing: $SRC" >&2
exit 1
fi
if ! command -v magick >/dev/null; then
echo "need: magick (ImageMagick 7)" >&2
exit 1
fi
mkdir -p "$OUT"
# 近白背景 → 透明JPG 白底)
magick "$SRC" -fuzz 12% -transparent white PNG32:"$TMP/fg.png"
# Android 自适应前景透明底1024内容约 78% 安全区)
magick "$TMP/fg.png" -resize '800x800>' -background none -gravity center -extent 1024x1024 \
PNG32:"$OUT/android-icon-foreground.png"
# 通用 / iOS 主图标(实色底)
magick -size 1024x1024 "xc:${BRAND_BG}" \( "$TMP/fg.png" -resize '800x800>' \) -gravity center -compose over -composite \
PNG32:"$OUT/icon.png"
# Android 13+ 单色层(白/透明)
magick "$OUT/android-icon-foreground.png" -alpha extract -fill white -colorize 100 -background none -alpha shape \
PNG32:"$OUT/android-icon-monochrome.png"
# 开屏图:仅透明 logo底色由 expo-splash-screen backgroundColor 填充)
magick "$SRC" -fuzz 12% -transparent white -resize '400x400>' PNG32:"$OUT/splash-icon.png"
magick "$OUT/icon.png" -resize 48x48 PNG32:"$OUT/favicon.png"
echo "OK → $OUT/icon.png, android-icon-foreground.png, android-icon-monochrome.png, splash-icon.png, favicon.png"