66 lines
1.6 KiB
Bash
Executable file
66 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Minimal PWA icon generator (no manifest/html)
|
|
# Outputs: icon-192.png, icon-512.png, icon-maskable-192.png, icon-maskable-512.png,
|
|
# apple-touch-icon.png (180x180), favicon.ico (16/32/48)
|
|
|
|
# Detect ImageMagick binary
|
|
if command -v magick >/dev/null 2>&1; then
|
|
IM="magick"
|
|
elif command -v convert >/dev/null 2>&1; then
|
|
IM="convert"
|
|
else
|
|
echo "Error: ImageMagick not found (need 'magick' or 'convert')." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $# -lt 2 ]]; then
|
|
echo "Usage: $0 <source-image> <output-dir>"
|
|
exit 1
|
|
fi
|
|
|
|
SRC="$1"
|
|
OUT="${2%/}"
|
|
mkdir -p "$OUT"
|
|
|
|
make_png() {
|
|
local size="$1" dest="$2"
|
|
$IM "$SRC" \
|
|
-alpha on -background none \
|
|
-resize "${size}x${size}" \
|
|
-gravity center -extent "${size}x${size}" \
|
|
"PNG32:${dest}"
|
|
}
|
|
|
|
make_maskable() {
|
|
local size="$1" dest="$2"
|
|
local inner=$(((size * 70) / 100))
|
|
$IM "$SRC" \
|
|
-alpha on -background none \
|
|
-resize "${inner}x${inner}" \
|
|
-gravity center -extent "${size}x${size}" \
|
|
"PNG32:${dest}"
|
|
}
|
|
|
|
echo "→ Generating core icons..."
|
|
make_png 192 "$OUT/icon-192.png"
|
|
make_png 512 "$OUT/icon-512.png"
|
|
make_maskable 192 "$OUT/icon-maskable-192.png"
|
|
make_maskable 512 "$OUT/icon-maskable-512.png"
|
|
make_png 180 "$OUT/apple-touch-icon.png"
|
|
|
|
echo "→ Generating favicon.ico..."
|
|
tmpdir="$(mktemp -d)"
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
|
|
for s in 16 32 48; do
|
|
$IM "$SRC" -alpha on -background none \
|
|
-resize "${s}x${s}" \
|
|
-gravity center -extent "${s}x${s}" \
|
|
"PNG32:${tmpdir}/${s}.png"
|
|
done
|
|
|
|
$IM "${tmpdir}/16.png" "${tmpdir}/32.png" "${tmpdir}/48.png" "$OUT/favicon.ico"
|
|
|
|
echo "✅ Done. Wrote minimal PWA icons to: $OUT"
|