kit-square.py
In web/At a9cd384Copy the commit ID
Preview
Code1.5 KiB"""Export a compact KIT wordmark fitted to a square favicon."""
from pathlib import Path
from copy import deepcopy
import sys
import struct
import subprocess
import xml.etree.ElementTree as E
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from source.logo import render, NS
logo = E.fromstring(render(False))
root = E.Element(NS + 'svg', {'width': '64', 'height': '64', 'viewBox': '0 0 64 64', 'role': 'img', 'aria-label': 'KIT'})
E.SubElement(root, NS + 'rect', {'width': '64', 'height': '64', 'rx': '14', 'fill': '#0067ed'})
letters = E.SubElement(root, NS + 'svg', {'x': '7', 'y': '12', 'width': '50', 'height': '40', 'viewBox': '7.62 50.66 66.5 19.79', 'preserveAspectRatio': 'none'})
for face in list(logo)[-3:]:
face = deepcopy(face)
face.set('fill', 'white')
letters.append(face)
art = ROOT / 'art/favicon'
art.mkdir(parents=True, exist_ok=True)
svg = art / 'kit-square.svg'
svg.write_text(E.tostring(root, encoding='unicode') + '\n')
images = []
for size in [16, 32, 48]:
png = ROOT / f'previews/favicon/kit-square-{size}.png'
subprocess.run(['rsvg-convert', '-w', str(size), '-h', str(size), '-o', str(png), str(svg)], check=True)
images.append((size, png.read_bytes()))
offset = 6 + 16 * len(images)
entries = []
for size, data in images:
entries.append(struct.pack('<BBBBHHII', size, size, 0, 0, 1, 32, len(data), offset))
offset += len(data)
(art / 'kit-square.ico').write_bytes(struct.pack('<HHH', 0, 1, len(images)) + b''.join(entries) + b''.join(data for _, data in images))