Skip to content

Palette-quantize generated brand PNGs#25

Merged
lesnik512 merged 8 commits into
mainfrom
brand-png-optimize
Jun 30, 2026
Merged

Palette-quantize generated brand PNGs#25
lesnik512 merged 8 commits into
mainfrom
brand-png-optimize

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Folds a palette-quantization pass into the brand build so every generated PNG is committed in compact indexed-colour form. The art is flat 2–3 colour, so quantizing rsvg-convert's 32-bit RGBA output to a palette is visually lossless and cuts the large assets ~70–80%:

  • social cards ~33–55 KB → ~9–15 KB
  • mark-1024 ~25–36 KB → ~8 KB
  • committed PNG footprint ~1.0 MB → ~0.3 MB

Done with Pillow (Image.Quantize.FASTOCTREE, 32-colour palette) in brand/build/raster.py::_quantize_png, called at the end of export_png — no Node, no required system binary. FASTOCTREE preserves alpha, so transparent marks keep clean edges (verified on light/dark). SVGs are deliberately untouched.

Design

  • Spec: planning/changes/2026-06-30.03-png-optimization/design.md
  • Plan: same bundle's plan.md

Notes

  • Re-rendering is deterministic (FASTOCTREE) — no spurious PNG churn.
  • Tests (tests/test_pngopt.py) assert indexed mode, dimensions, transparency on the marks, size ceilings, and palette reduction; output is pristine. 91 tests pass; just check-planning OK.
  • Out of scope: SVG optimization, external optimizers (pngquant/oxipng), the 1280×640-vs-1200×630 ratio, and re-copying the smaller cards into the 7 docs-repo PRs (a follow-up).

🤖 Generated with Claude Code

lesnik512 and others added 8 commits June 30, 2026 17:04
Palette-quantize generated PNGs (Pillow FASTOCTREE) in raster.py — ~70-80%
smaller, visually lossless for flat art, alpha preserved on transparent marks.
SVGs and external optimizers out of scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Two tasks: add Pillow + the FASTOCTREE quantize step in raster.py (with tests and
regenerated PNGs), then docs/finalize.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 62d1425 into main Jun 30, 2026
1 check passed
@lesnik512 lesnik512 deleted the brand-png-optimize branch June 30, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant