fix: icon centering — use Center gravity with signed offsets
Previous script used NorthWest gravity with fixed pixel offsets, placing the BR pair in the upper-left quadrant. When Android clips to a circle the letters appeared off-center. New approach: -gravity Center with ±HALF offsets so each letter is symmetrically placed around the canvas centre mathematically. No subshells, no pixel guesswork. Regenerated all four icon assets.
This commit is contained in:
+35
-27
@@ -1,7 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generates all icon assets for bincio-rec.
|
||||
# Requires ImageMagick (magick / convert).
|
||||
# Style mirrors bincio_autarchive: dark background, white B, accent-coloured R.
|
||||
# Requires ImageMagick 7 (magick).
|
||||
#
|
||||
# Centering strategy: both letters are rendered with -gravity Center.
|
||||
# Each letter's centre is offset ±HALF pixels from the canvas centre,
|
||||
# where HALF = (letter_width + gap) / 2. This gives mathematically
|
||||
# correct horizontal & vertical centering regardless of font metrics.
|
||||
|
||||
set -e
|
||||
cd "$(dirname "$0")/.."
|
||||
@@ -11,33 +15,37 @@ BG="#09090b"
|
||||
WHITE="#ffffff"
|
||||
RED="#ef4444"
|
||||
|
||||
# ── Main icon (1024×1024) ─────────────────────────────────────────────────────
|
||||
magick -size 1024x1024 xc:"$BG" \
|
||||
-font "$FONT" \
|
||||
-pointsize 480 -fill "$WHITE" -gravity NorthWest -annotate +110+295 'B' \
|
||||
-pointsize 480 -fill "$RED" -gravity NorthWest -annotate +560+295 'R' \
|
||||
assets/icon.png
|
||||
# render_br CANVAS BG SIZE HALF OUT
|
||||
# HALF = how many pixels each letter centre is offset from canvas centre.
|
||||
render_br() {
|
||||
local CANVAS=$1 BG_COL=$2 SIZE=$3 HALF=$4 OUT=$5
|
||||
magick -size "${CANVAS}x${CANVAS}" xc:"$BG_COL" \
|
||||
-font "$FONT" -pointsize "$SIZE" -gravity Center \
|
||||
-fill "$WHITE" -annotate "-${HALF}+0" 'B' \
|
||||
-fill "$RED" -annotate "+${HALF}+0" 'R' \
|
||||
"$OUT"
|
||||
}
|
||||
|
||||
# ── Android adaptive icon — foreground (transparent bg, design fits safe zone)
|
||||
# Safe zone = inner 66% of 1024 = 676 px.
|
||||
magick -size 1024x1024 xc:none \
|
||||
-font "$FONT" \
|
||||
-pointsize 340 -fill "$WHITE" -gravity NorthWest -annotate +175+325 'B' \
|
||||
-pointsize 340 -fill "$RED" -gravity NorthWest -annotate +535+325 'R' \
|
||||
assets/android-icon-foreground.png
|
||||
# render_br_transparent CANVAS SIZE HALF B_FILL R_FILL OUT
|
||||
render_br_transparent() {
|
||||
local CANVAS=$1 SIZE=$2 HALF=$3 B_FILL=$4 R_FILL=$5 OUT=$6
|
||||
magick -size "${CANVAS}x${CANVAS}" xc:none \
|
||||
-font "$FONT" -pointsize "$SIZE" -gravity Center \
|
||||
-fill "$B_FILL" -annotate "-${HALF}+0" 'B' \
|
||||
-fill "$R_FILL" -annotate "+${HALF}+0" 'R' \
|
||||
"$OUT"
|
||||
}
|
||||
|
||||
# ── Android adaptive icon — monochrome (white on transparent, for themed icons)
|
||||
magick -size 1024x1024 xc:none \
|
||||
-font "$FONT" \
|
||||
-pointsize 340 -fill "$WHITE" -gravity NorthWest -annotate +175+325 'B' \
|
||||
-pointsize 340 -fill "$WHITE" -gravity NorthWest -annotate +535+325 'R' \
|
||||
assets/android-icon-monochrome.png
|
||||
# At 480 pt NotoSans-Bold, each capital is ~320 px wide.
|
||||
# Gap between inner edges: 60 px. Inter-centre: 320 + 60 = 380 → HALF = 190.
|
||||
render_br 1024 "$BG" 480 190 assets/icon.png
|
||||
|
||||
# ── Splash screen icon (512×512) ─────────────────────────────────────────────
|
||||
magick -size 512x512 xc:"$BG" \
|
||||
-font "$FONT" \
|
||||
-pointsize 240 -fill "$WHITE" -gravity NorthWest -annotate +55+147 'B' \
|
||||
-pointsize 240 -fill "$RED" -gravity NorthWest -annotate +280+147 'R' \
|
||||
assets/splash-icon.png
|
||||
# Adaptive foreground (transparent, fits the 66% safe zone).
|
||||
# 320 pt → letter ~215 px wide. Gap 50 px → HALF = 132.
|
||||
render_br_transparent 1024 320 132 "$WHITE" "$RED" assets/android-icon-foreground.png
|
||||
render_br_transparent 1024 320 132 "$WHITE" "$WHITE" assets/android-icon-monochrome.png
|
||||
|
||||
# Splash 512×512 — 240 pt → letter ~160 px wide. Gap 36 px → HALF = 98.
|
||||
render_br 512 "$BG" 240 98 assets/splash-icon.png
|
||||
|
||||
echo "✓ Icon assets generated in assets/"
|
||||
|
||||
Reference in New Issue
Block a user