Files
bincio-rec/scripts/generate_icons.sh
T
Davide Scaini ccfc60934a 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.
2026-06-04 01:04:02 +02:00

52 lines
1.9 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
# Generates all icon assets for bincio-rec.
# 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")/.."
FONT="$HOME/Library/Fonts/NotoSans-Bold.ttf"
BG="#09090b"
WHITE="#ffffff"
RED="#ef4444"
# 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"
}
# 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"
}
# 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
# 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/"