Files
slp-modular-cms/frontend/themes/slpsoftware/make-logo.py
T
SluijsensandClaude Sonnet 5.5 321234dfa6 CMS: één bannerlijst met Locatie, SLP-thema, thema-schakelaar, documentatie
- Banner-admin: één lijst met Locatie-badge (Boven/Onder), Locatie-keuzeveld in het formulier, "Live" en "Wordt niet getoond" per locatie, aan/uit per rij
- Thema slpsoftware: Archivo, bordeaux #7A1414 (WCAG AA licht en donker), <SLP/>-logo, favicon, mail-logo; VITE_THEME in de SLP-builds (test en productie-config)
- Thema-schakelaar: eerste klik wisselt altijd het getoonde thema (klasse op <html> als bron van waarheid, gedeelde status, startscript valideert opslag) + tests
- Docs: README, docs/cms-themas.md, docs/deploy-en-testomgevingen.md, docs/privacy-gegevens-contactformulier.md, aidlc-docs (offering-banners, bug theme-toggle-first-click)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 00:14:10 +01:00

101 lines
3.8 KiB
Python

"""
Builds the SLP Software brand logo: logo-on-light.png, logo-on-dark.png, logo-mail.png and logo.svg.
The mark is the text <SLP/> in Archivo ExtraBold; the angle brackets and slash are bordeaux accents,
"SLP" is ink. Displayed 40 px high in the admin; PNGs are rendered at 3x (about 120 px high).
Needs: pip install pillow fonttools brotli; and `pnpm install` in frontend/ (font comes from @fontsource/archivo).
Run from this folder: python make-logo.py
"""
import io
import os
from fontTools.ttLib import TTFont
from fontTools.pens.svgPathPen import SVGPathPen
from PIL import Image, ImageDraw, ImageFont
SCALE = 3
H = 40 * SCALE
PAD = 2 * SCALE
FONT_WOFF2 = "../../node_modules/@fontsource/archivo/files/archivo-latin-800-normal.woff2"
TTF = "archivo-800.tmp.ttf"
PARTS = [("<", "accent"), ("SLP", "ink"), ("/>", "accent")]
VARIANTS = {
"logo-on-light.png": {"ink": (26, 26, 26), "accent": (122, 20, 20)},
"logo-on-dark.png": {"ink": (245, 245, 245), "accent": (224, 100, 108)},
}
f = TTFont(FONT_WOFF2)
f.flavor = None
f.save(TTF)
# Pick the pixel size so that the ink bounding box of the whole text is about H - 2*PAD high.
size = 100
probe = ImageFont.truetype(TTF, size)
text = "".join(p for p, _ in PARTS)
b = probe.getbbox(text)
size = round(size * (H - 2 * PAD) / (b[3] - b[1]))
font = ImageFont.truetype(TTF, size)
full = font.getbbox(text)
asc_top, asc_bot = full[1], full[3]
def render(colors):
# Draw the parts one after another using advance widths (keeps the font's own kerning-free spacing).
width = round(font.getlength(text)) + 2 * PAD + 4
img = Image.new("RGBA", (width, 2 * H), (0, 0, 0, 0))
d = ImageDraw.Draw(img)
x = PAD
for part, role in PARTS:
d.text((x, PAD - asc_top), part, font=font, fill=colors[role] + (255,))
x += font.getlength(part)
img = img.crop(img.getchannel("A").getbbox())
out = Image.new("RGBA", (img.width + 2 * PAD, img.height + 2 * PAD), (0, 0, 0, 0))
out.alpha_composite(img, (PAD, PAD))
return out
for name, colors in VARIANTS.items():
im = render(colors)
im.save(name, optimize=True)
print(f"{name} {im.width}x{im.height}")
# logo-mail.png: the light variant on a white rounded badge (same approach as themes/asf/make-mail-logo.py).
src = Image.open("logo-on-light.png").convert("RGBA")
src = src.crop(src.getchannel("A").getbbox())
CONTENT_H, MPAD, RADIUS = 40 * SCALE, 8 * SCALE, 8 * SCALE
logo = src.resize((round(src.width * CONTENT_H / src.height), CONTENT_H), Image.LANCZOS)
w, h = logo.width + 2 * MPAD, CONTENT_H + 2 * MPAD
badge = Image.new("RGBA", (w, h), (0, 0, 0, 0))
ImageDraw.Draw(badge).rounded_rectangle((0, 0, w - 1, h - 1), radius=RADIUS, fill=(255, 255, 255, 255))
badge.alpha_composite(logo, (MPAD, MPAD))
badge.save("logo-mail.png", optimize=True)
print(f"logo-mail.png {w}x{h}")
# logo.svg: text converted to paths (archive/source; the build uses the PNGs).
gs = f.getGlyphSet()
cmap = f.getBestCmap()
upm = f["head"].unitsPerEm
hmtx = f["hmtx"]
paths, x = [], 0
ymin, ymax = 10**9, -10**9
from fontTools.pens.boundsPen import BoundsPen
for part, role in PARTS:
for ch in part:
g = cmap[ord(ch)]
pen = SVGPathPen(gs)
gs[g].draw(pen)
bp = BoundsPen(gs)
gs[g].draw(bp)
if bp.bounds:
ymin, ymax = min(ymin, bp.bounds[1]), max(ymax, bp.bounds[3])
paths.append((pen.getCommands(), x, role))
x += hmtx[g][0]
pad = 20
vb_h = ymax - ymin + 2 * pad
fill = {"ink": "#1a1a1a", "accent": "#7a1414"}
body = "\n".join(
f' <path fill="{fill[r]}" transform="translate({px} {ymax + pad}) scale(1 -1)" d="{d}"/>' for d, px, r in paths
)
svg = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="{-pad} 0 {x + 2 * pad} {vb_h}" role="img" aria-label="SLP Software">\n{body}\n</svg>\n'
open("logo.svg", "w", encoding="utf-8", newline="\n").write(svg)
print("logo.svg", len(svg), "bytes")
os.remove(TTF)