Skip to content

A comprehensive logo-design skill for Claude, Gemini CLI, Codex and other AI agents: principles, process, SVG craft, testing tools and a 1,400+ logo reference library.

Improve presentation and rendering tools (v1.2.0)

Kaanf543c0c0f001
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json
index ba49361..ccc51bf 100644
--- a/.claude-plugin/marketplace.json
+++ b/.claude-plugin/marketplace.json
@@ -6,14 +6,14 @@
},
"metadata": {
"description": "A comprehensive logo-design skill for Claude: principles, process, SVG craft, testing tools and a 1,432-logo reference library.",
- "version": "1.1.0"
+ "version": "1.2.0"
},
"plugins": [
{
"name": "logo-design",
"source": "./",
"description": "Design, critique and deliver professional logos: brief, concepts, geometric SVG construction, optical refinement, colour, typography, testing, presentation and brand guidelines — with a searchable library of 1,432 classified SVG logos.",
- "version": "1.1.0",
+ "version": "1.2.0",
"category": "design",
"keywords": ["logo", "branding", "identity", "svg", "design", "wordmark", "icon"]
}
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json
index 7e58329..0138e47 100644
--- a/.claude-plugin/plugin.json
+++ b/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "logo-design",
"description": "Design, critique and deliver professional logos: brief, concepts, geometric SVG construction, optical refinement, colour, typography, testing, presentation and brand guidelines — with a searchable library of 1,432 classified SVG logos.",
- "version": "1.1.0",
+ "version": "1.2.0",
"author": {
"name": "kaankiziltug",
"url": "https://github.com/kaankiziltug"
diff --git a/skills/logo-design/SKILL.md b/skills/logo-design/SKILL.md
index d5c4311..ce04bb0 100644
--- a/skills/logo-design/SKILL.md
+++ b/skills/logo-design/SKILL.md
@@ -45,8 +45,8 @@ All scripts are dependency-free Python 3 and live in this skill's `scripts/` fol
| `search_library.py` | Find reference logos by `--type`, `--technique`, `--geometry`, `--subject`, `--industry`, `--color`, `--mood`…; `--summary` shows a category's conventions; `--format paths` gives files to read |
| `svg_audit.py` | Check an SVG: live text, rasters, filters, colour count, gradients, strokes, near-miss angles, tiny details, centring, complexity vs. the library |
| `preview_sheet.py` | HTML test sheet: size ladder, 16/32 px pixel test, backgrounds, one-colour, squint blur, mirror/rotate, favicon/app-icon/header/card contexts, side-by-side, shelf test vs. competitors |
-| `presentation_board.py` | Client presentation (brief, each concept with rationale + 6 **industry-specific** mockups — cup, packaging, README, terminal, signage…; comparison, recommendation) from a JSON spec (`templates/presentation-spec.example.json`); `--list-mockups` |
-| `render_png.py` | Render SVG → transparent PNG at exact sizes (for looking at your work and for deliverables); builds `favicon.ico`; `--which` lists renderers |
+| `presentation_board.py` | Client presentation (brief, each concept with rationale + 6 **industry-specific** mockups — cup, packaging, README, terminal, signage…; comparison, recommendation) from a JSON spec (`templates/presentation-spec.example.json`); `--png-dir` exports every slide as PNG; `--list-mockups` |
+| `render_png.py` | Render SVG → transparent PNG at exact sizes (for looking at your work and for deliverables); screenshots HTML sheets/boards (Chrome); builds `favicon.ico`; `--which` lists renderers |
| `export_variants.py` | Black, white, brand-mono, square, favicon and app-icon SVGs; `--png` sizes; `--web-icons` = favicon.ico + PNG icon set + webmanifest + `<head>` snippet; `--favicon-source` for a simplified small-size drawing |
| `build_catalog.py` | Maintainers only: rebuild the library catalog |
diff --git a/skills/logo-design/scripts/build_catalog.py b/skills/logo-design/scripts/build_catalog.py
index 5d211a8..bbaa1d5 100644
--- a/skills/logo-design/scripts/build_catalog.py
+++ b/skills/logo-design/scripts/build_catalog.py
@@ -20,6 +20,7 @@ import statistics
import sys
from collections import Counter
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import svglib # noqa: E402
diff --git a/skills/logo-design/scripts/concept_sheet.py b/skills/logo-design/scripts/concept_sheet.py
index 8ad9078..bac44cb 100644
--- a/skills/logo-design/scripts/concept_sheet.py
+++ b/skills/logo-design/scripts/concept_sheet.py
@@ -20,6 +20,7 @@ import os
import re
import sys
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import render_png # noqa: E402
import svglib # noqa: E402
@@ -74,7 +75,16 @@ def main():
card_w = (W - 2 * pad - (cols - 1) * gap) / cols
has_lock = bool(a.lockups)
art_h = 300
- lock_h = 120 if has_lock else 0
+ lock_h = 0
+ if has_lock:
+ ratios = []
+ for lp in a.lockups:
+ if lp:
+ vb = svglib.view_box(svglib.load_svg(lp)[1])
+ if vb and vb[3]:
+ ratios.append(vb[2] / vb[3])
+ # wide lockups fit a short slot; squarish ones (emblems, stacked lockups) need more height
+ lock_h = 120 if not ratios or min(ratios) >= 2.2 else (170 if min(ratios) >= 1.4 else 210)
card_h = 40 + art_h + (lock_h + 24 if has_lock else 0) + 90 + 150 + (30 if a.recommend else 0) + 20
header = 150
H = header + rows * card_h + (rows - 1) * gap + pad
diff --git a/skills/logo-design/scripts/export_variants.py b/skills/logo-design/scripts/export_variants.py
index d9115e5..0f81dd0 100644
--- a/skills/logo-design/scripts/export_variants.py
+++ b/skills/logo-design/scripts/export_variants.py
@@ -35,6 +35,7 @@ import re
import sys
import tempfile
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import svglib # noqa: E402
import render_png # noqa: E402
diff --git a/skills/logo-design/scripts/presentation_board.py b/skills/logo-design/scripts/presentation_board.py
index b82b566..7733f1a 100644
--- a/skills/logo-design/scripts/presentation_board.py
+++ b/skills/logo-design/scripts/presentation_board.py
@@ -8,6 +8,7 @@ round; set "greyscale": false for colour, and "final": true for a single final-d
Usage:
python3 scripts/presentation_board.py spec.json -o presentation.html
+ python3 scripts/presentation_board.py spec.json -o board.html --png-dir slides # + one PNG per slide
python3 scripts/presentation_board.py --list-mockups
spec.json (paths relative to the spec file; see templates/presentation-spec.example.json):
@@ -18,12 +19,13 @@ spec.json (paths relative to the spec file; see templates/presentation-spec.exam
"nav": ["Shop", "Cafés", "Story"], # optional website menu items
"brand_color": "#B5532F", "greyscale": true, "final": false, "round": 1,
"concepts": [
- {"name": "Kiln K", "symbol": "b-symbol.svg", "lockup": "b-horizontal.svg", "avatar": "b-avatar.svg",
+ {"name": "Kiln K", "symbol": "b-symbol.svg", "lockup": "b-horizontal.svg", "stacked": "b-stacked.svg", "avatar": "b-avatar.svg",
"idea": "One sentence.", "rationale": ["…", "…"]}
],
"recommendation": "…"
}
-Each concept needs at least one of symbol / lockup / avatar; missing ones fall back sensibly
+Each concept needs at least one of symbol / lockup / avatar; "stacked" (optional) is used on bags, signs and badges.
+Missing ones fall back sensibly
(a wordmark-only concept can provide just "lockup" plus an "avatar" for small uses).
"""
import argparse
@@ -33,6 +35,7 @@ import json
import os
import sys
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import svglib # noqa: E402
@@ -79,7 +82,7 @@ ul.rat{padding-left:18px;margin:0}ul.rat li{margin:6px 0}
.bc{width:250px;height:143px;background:#fff;border-radius:5px;box-shadow:0 10px 26px rgba(0,0,0,.22);padding:16px;display:flex;flex-direction:column;justify-content:space-between;transform:translate(-50px,-38px) rotate(-4deg)}
.bc2{position:absolute;width:250px;height:143px;border-radius:5px;transform:translate(70px,52px) rotate(6deg);box-shadow:0 10px 26px rgba(0,0,0,.25);display:flex;align-items:center;justify-content:center}
.bc .t{font-size:9px;line-height:1.5;color:#333}
-.phone{width:150px;height:250px;border-radius:26px;background:#10151c;padding:10px;box-shadow:0 10px 30px rgba(0,0,0,.3)}
+.phone{width:172px;height:250px;border-radius:26px;background:#10151c;padding:10px;box-shadow:0 10px 30px rgba(0,0,0,.3)}
.screen{width:100%;height:100%;border-radius:18px;background:linear-gradient(170deg,#e9edf1,#cfd7df);display:grid;grid-template-columns:repeat(3,1fr);gap:10px;padding:18px 12px;align-content:start}
.ai{width:34px;height:34px;border-radius:9px;background:rgba(0,0,0,.08);justify-self:center}
.web{width:340px;height:210px;background:#fff;border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.15);overflow:hidden}
@@ -137,6 +140,7 @@ def uri(path, base):
def mock_html(kind, c):
"""c: dict with sym, lock, avatar, color, cls, name, tag, nav."""
sym, lock, av, cls, name, tag = c["sym"], c["lock"], c["avatar"], c["cls"], c["name"], c["tag"]
+ stack = c.get("stacked") or lock # stacked lockup for tall/boxy surfaces (bags, signs, badges) when provided
tile = c["tile"]
handle = html.escape(name.lower().replace(" ", ""))
n = html.escape(name)
@@ -157,7 +161,7 @@ def mock_html(kind, c):
f'<div class="hero2"><b>{html.escape(tag) or n}</b><span></span><span style="width:60%"></span></div></div><span class="lbl">Website</span></div>')
if kind == "signage":
return (f'<div class="m" style="background:#b9bcc0"><div class="sign"><div class="board" style="background:#161616">'
- f'<img class="w" src="{lock}" style="max-height:34px;max-width:190px"></div><div class="door"></div></div><span class="lbl">Storefront / signage</span></div>')
+ f'<img class="w" src="{stack}" style="max-height:{58 if stack != lock else 34}px;max-width:190px"></div><div class="door"></div></div><span class="lbl">Storefront / signage</span></div>')
if kind == "tote":
return (f'<div class="m" style="background:#cfc6b6"><div class="tote"><img class="k" src="{av}" style="max-height:80px;max-width:110px;opacity:.88"></div>'
'<span class="lbl">Tote bag</span></div>')
@@ -174,7 +178,7 @@ def mock_html(kind, c):
f'<img class="{cls}" src="{lock}" style="max-height:18px;max-width:120px"><div class="t">{html.escape(tag)[:40]}</div></div>'
'<span class="lbl">Packaging bag</span></div>')
if kind == "shopping-bag":
- return (f'<div class="m" style="background:#e3ded6"><div class="sbag" style="background:{tile}"><img class="w" src="{lock}" style="max-height:40px;max-width:130px"></div>'
+ return (f'<div class="m" style="background:#e3ded6"><div class="sbag" style="background:{tile}"><img class="w" src="{stack}" style="max-height:{96 if stack != lock else 40}px;max-width:130px"></div>'
'<span class="lbl">Shopping bag</span></div>')
if kind == "box":
return (f'<div class="m" style="background:#d6d9dc"><div class="box"><img class="{cls}" src="{lock}" style="max-height:44px;max-width:160px"></div>'
@@ -196,7 +200,7 @@ def mock_html(kind, c):
return (f'<div class="m" style="background:#e4e1dc"><div class="shirt">{shirt}<img class="w" src="{av}" style="position:relative;max-height:56px;max-width:70px;margin-top:10px"></div>'
'<span class="lbl">T-shirt</span></div>')
if kind == "badge":
- return (f'<div class="m" style="background:#d9dde2"><div class="badge"><div class="hole"></div><img class="{cls}" src="{lock}" style="max-height:34px;max-width:130px">'
+ return (f'<div class="m" style="background:#d9dde2"><div class="badge"><div class="hole"></div><img class="{cls}" src="{stack}" style="max-height:{70 if stack != lock else 34}px;max-width:130px">'
'<div class="nm">Alex Morgan</div><div class="rl">Speaker</div></div><span class="lbl">Event badge</span></div>')
if kind == "favicon-tab":
return (f'<div class="m" style="background:#eceff1"><div class="tabbar"><div class="tab"><img class="{cls}" src="{av}" style="width:16px;height:16px;object-fit:contain">'
@@ -223,6 +227,7 @@ def main():
ap.add_argument("spec", nargs="?")
ap.add_argument("-o", "--out", default="presentation.html")
ap.add_argument("--list-mockups", action="store_true")
+ ap.add_argument("--png-dir", help="also export every slide as slide-NN.png (needs Chrome/Chromium)")
a = ap.parse_args()
if a.list_mockups:
print("mockups:", ", ".join(ALL_MOCKUPS))
@@ -253,12 +258,22 @@ def main():
return f'<div class="foot"><span>{html.escape(brand)} — {html.escape(deck_title)}</span><span>{i}</span></div>'
slides = []
- kicker = "Final identity" if final else f"Logo design · round {spec.get('round', 1)}"
+ custom_title = spec.get("deck_title")
+ cover_mark = ""
+ if final and concepts:
+ c0 = concepts[0]
+ first = c0.get("lockup") or c0.get("symbol") or c0.get("avatar")
+ if first:
+ cover_mark = (f'<div style="position:absolute;right:64px;top:50%;transform:translateY(-50%);width:520px;'
+ f'height:300px;display:flex;align-items:center;justify-content:center">'
+ f'<img class="{cls}" src="{uri(first, base)}" style="max-width:100%;max-height:100%"></div>')
+ kicker = (custom_title.capitalize() if (final and custom_title) else "Final identity") if final \
+ else f"Logo design · round {spec.get('round', 1)}"
note = ("Concepts are shown in greyscale so the conversation stays on form and idea; colour follows once a "
"direction is chosen." if grey and not final else "")
slides.append(f"""<section class="slide"><div class="kicker">{kicker}</div>
<h1>{html.escape(brand)}</h1><p class="idea muted">{html.escape(deck_title.capitalize())}{(' · ' + html.escape(designer)) if designer else ''} · {date}</p>
-<p class="muted" style="max-width:720px;margin-top:120px">{note}</p>{foot(1)}</section>""")
+{cover_mark}<p class="muted" style="max-width:720px;margin-top:120px">{note}</p>{foot(1)}</section>""")
adj = "".join(f"<span>{html.escape(x)}</span>" for x in spec.get("adjectives", []))
crit = spec.get("criteria", "Success: distinctive in its category, recognisable at 16 px, works in one colour, "
"and feels like the words above.")
@@ -274,8 +289,10 @@ def main():
sym = uri(c.get("symbol") or c.get("avatar") or c.get("lockup"), base)
lock = uri(c.get("lockup") or c.get("symbol") or c.get("avatar"), base)
av = uri(c.get("avatar") or c.get("symbol") or c.get("lockup"), base)
+ stacked = uri(c["stacked"], base) if c.get("stacked") else None
items.append((c, sym, lock))
- label = "Final design" if final else f"Concept {chr(65 + i)}"
+ label = spec.get("label") or ((custom_title.capitalize() if custom_title else "Final design") if final
+ else f"Concept {chr(65 + i)}")
rat = "".join(f"<li>{html.escape(r)}</li>" for r in c.get("rationale", []))
sizes = "".join(f'<div><img class="{cls}" src="{av}" style="height:{s}px">{s}px</div>' for s in (16, 24, 32, 64))
slides.append(f"""<section class="slide"><div class="kicker">{label}</div><h2>{html.escape(c.get('name', ''))}</h2>
@@ -284,7 +301,7 @@ def main():
<div><ul class="rat">{rat}</ul><div class="sizes">{sizes}</div><div class="rev"><img class="w" src="{lock}" style="max-height:44px;max-width:300px"></div></div></div>
{foot(len(slides) + 1)}</section>""")
ctx = {"sym": sym, "lock": lock, "avatar": av, "cls": cls, "name": brand, "tag": spec.get("tagline", ""),
- "tile": tile, "nav": nav}
+ "tile": tile, "nav": nav, "stacked": stacked}
cells = "".join(mock_html(k, ctx) for k in mockups)
slides.append(f"""<section class="slide"><div class="kicker">{label} · in use</div><h2>{html.escape(c.get('name', ''))}</h2>
<div class="mock">{cells}</div>{foot(len(slides) + 1)}</section>""")
@@ -308,6 +325,24 @@ def main():
with open(a.out, "w", encoding="utf-8") as fh:
fh.write(doc)
print(f"wrote {a.out} ({len(slides)} slides; mockups: {', '.join(mockups)})")
+ if a.png_dir:
+ import tempfile
+ import render_png
+ os.makedirs(a.png_dir, exist_ok=True)
+ solo_css = CSS + "body{background:#fff}.slide{margin:0;box-shadow:none;min-height:800px}"
+ for i, sl in enumerate(slides, 1):
+ with tempfile.NamedTemporaryFile("w", suffix=".html", delete=False, encoding="utf-8") as fh:
+ fh.write(f"<!doctype html><html><head><meta charset='utf-8'><style>{solo_css}</style></head><body>{sl}</body></html>")
+ tmp_html = fh.name
+ out = os.path.join(a.png_dir, f"slide-{i:02d}.png")
+ try:
+ render_png.screenshot_html(tmp_html, out, 1280, 800)
+ print("wrote", out)
+ except Exception as exc:
+ print(f"slide PNG export failed ({exc}); open the HTML instead")
+ break
+ finally:
+ os.unlink(tmp_html)
if __name__ == "__main__":
diff --git a/skills/logo-design/scripts/preview_sheet.py b/skills/logo-design/scripts/preview_sheet.py
index 41d6ae5..ead60d5 100644
--- a/skills/logo-design/scripts/preview_sheet.py
+++ b/skills/logo-design/scripts/preview_sheet.py
@@ -23,6 +23,7 @@ import os
import random
import sys
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import svglib # noqa: E402
diff --git a/skills/logo-design/scripts/render_png.py b/skills/logo-design/scripts/render_png.py
index 6d676dd..93905a5 100644
--- a/skills/logo-design/scripts/render_png.py
+++ b/skills/logo-design/scripts/render_png.py
@@ -16,6 +16,7 @@ Usage:
python3 scripts/render_png.py symbol.svg -o preview.png --size 256 --bg "#ffffff"
python3 scripts/render_png.py a.svg b.svg c.svg --out-dir renders --size 400 # batch, for viewing
python3 scripts/render_png.py favicon.svg --ico favicon.ico --ico-sizes 16 32 48
+ python3 scripts/render_png.py preview.html -o preview.png --width 1400 --height 3000 # screenshot an HTML page (Chrome)
python3 scripts/render_png.py --which # show available backends
"""
import argparse
@@ -123,7 +124,6 @@ def _inkscape(svg_file, png, w, h):
def _chrome(svg_file, png, w, h):
- chrome = find_chrome()
with open(svg_file, "rb") as fh:
data = base64.b64encode(fh.read()).decode("ascii")
page = (f"<!doctype html><html><head><style>html,body{{margin:0;padding:0;background:transparent;width:{w}px;"
@@ -131,9 +131,19 @@ def _chrome(svg_file, png, w, h):
f"<body><img src='data:image/svg+xml;base64,{data}'></body></html>")
with tempfile.TemporaryDirectory() as tmp:
html_path = os.path.join(tmp, "render.html")
- shot = os.path.join(tmp, "shot.png") # never poll the destination: an older file may already exist there
with open(html_path, "w", encoding="utf-8") as fh:
fh.write(page)
+ screenshot_html(html_path, png, w, h)
+
+
+def screenshot_html(html_path, png, w, h):
+ """Screenshot an HTML page (viewport w×h, transparent where the page is) with headless Chrome/Chromium."""
+ chrome = find_chrome()
+ if not chrome:
+ raise RuntimeError("no Chromium-based browser found for HTML screenshots")
+ html_path = os.path.abspath(html_path)
+ with tempfile.TemporaryDirectory() as tmp:
+ shot = os.path.join(tmp, "shot.png") # never poll the destination: an older file may already exist there
cmd = [chrome, "--headless=new", "--disable-gpu", "--hide-scrollbars", "--no-first-run",
"--no-default-browser-check", "--use-mock-keychain", "--password-store=basic", "--disable-extensions",
"--default-background-color=00000000", f"--window-size={w},{h}", f"--screenshot={shot}",
@@ -295,6 +305,17 @@ def main():
rc = 0
for f in a.files:
+ if f.lower().endswith((".html", ".htm")):
+ out = a.out if (a.out and len(a.files) == 1) else os.path.join(a.out_dir or os.path.dirname(os.path.abspath(f)),
+ os.path.splitext(os.path.basename(f))[0] + ".png")
+ w, h = a.width or 1400, a.height or 900
+ try:
+ screenshot_html(f, out, w, h)
+ print(f"wrote {out} {w}×{h} via chrome (HTML screenshot)")
+ except Exception as exc:
+ rc = 1
+ print(f"could not screenshot {f}: {exc}")
+ continue
if a.out and len(a.files) == 1:
out = a.out
else:
diff --git a/skills/logo-design/scripts/search_library.py b/skills/logo-design/scripts/search_library.py
index a393ed8..0fec6e4 100644
--- a/skills/logo-design/scripts/search_library.py
+++ b/skills/logo-design/scripts/search_library.py
@@ -21,6 +21,7 @@ import os
import sys
from collections import Counter
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import svglib # noqa: E402
diff --git a/skills/logo-design/scripts/svg_audit.py b/skills/logo-design/scripts/svg_audit.py
index 741061a..676d6ff 100644
--- a/skills/logo-design/scripts/svg_audit.py
+++ b/skills/logo-design/scripts/svg_audit.py
@@ -20,6 +20,7 @@ import os
import re
import sys
+sys.dont_write_bytecode = True # keep the skill folder clean (no __pycache__)
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import svglib # noqa: E402
@@ -164,7 +165,8 @@ def audit(path, bg=None):
if near:
sample = "; ".join(f"{x[0]}° (→{x[1]}°) len {x[2]} at ({x[3][0]:.0f},{x[3][1]:.0f})" for x in near[:6])
add("WARN", "near-miss-angle", f"{len(near)} straight edge(s) are 0.3–3° off a clean angle — they read as "
- f"mistakes. Snap them: {sample}" + (" …" if len(near) > 6 else ""))
+ f"mistakes. Snap them: {sample}" + (" …" if len(near) > 6 else "") +
+ ". (Expected — and fine — for type set on a curve or deliberately rotated elements.)")
# tiny details — symbols must survive ~48 px, lockups ~32 px of height
if info.get("aspect_class") in ("wide", "horizontal", "extra-wide"):
ref, label = vb[3] / 32, "1/32 of the lockup height (≈1 px at 32 px tall)"
diff --git a/skills/logo-design/scripts/svglib.py b/skills/logo-design/scripts/svglib.py
index bf5a83b..831385c 100644
--- a/skills/logo-design/scripts/svglib.py
+++ b/skills/logo-design/scripts/svglib.py
@@ -40,8 +40,24 @@ def load_svg(path):
def svg_data_uri(path):
+ """Base64 data URI for <img> use. Adds width/height from the viewBox when missing, because browsers give
+ viewBox-only SVGs a default 300×150 box (or none) and they can vanish inside flex/max-height layouts."""
with open(path, "rb") as fh:
- return "data:image/svg+xml;base64," + base64.b64encode(fh.read()).decode("ascii")
+ data = fh.read()
+ text = data.decode("utf-8", errors="ignore")
+ m = re.search(r"<svg\b[^>]*>", text)
+ if m:
+ tag = m.group(0)
+ has_w = re.search(r'\swidth\s*=\s*"', tag)
+ has_h = re.search(r'\sheight\s*=\s*"', tag)
+ vb = re.search(r'viewBox\s*=\s*"([^"]+)"', tag)
+ if vb and not (has_w and has_h):
+ parts = [p for p in re.split(r"[ ,]+", vb.group(1).strip()) if p]
+ if len(parts) == 4:
+ new_tag = re.sub(r'\s(width|height)\s*=\s*"[^"]*"', "", tag)
+ new_tag = new_tag[:-1].rstrip("/") + f' width="{parts[2]}" height="{parts[3]}">'
+ data = text.replace(tag, new_tag, 1).encode("utf-8")
+ return "data:image/svg+xml;base64," + base64.b64encode(data).decode("ascii")
# ----------------------------------------------------------------------------- colours