Skip to content

Compress rendered images with Sharp and compare PNG/WebP outputs - #8

Merged
GTrunSec merged 3 commits into
mainfrom
feat/render-image-compression
Nov 5, 2026
Merged

GTrunSec merged 3 commits into
mainfrom
feat/render-image-compression

Conversation

@GTrunSec

@GTrunSec GTrunSec commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Image export now uses pinned Sharp to produce lossless PNG and WebP and exposes preferredRaster with the actual smaller bytes, format and MIME. Existing PNG/region/SVG properties remain available; SVG stays the vector deliverable. Lossy WebP and palette PNG require explicit options, and WebP can be disabled.

The existing receipt records final PNG/WebP/region hashes, native encoder options and byte counts. PNG retains the original only if it is a valid PNG and re-encoding would grow it. Invalid settings and corrupt/foreign PNG inputs reject through browser-context cleanup. No resizer, global Sharp configuration, external optimization process or publisher is added.

Real-case comparison: 38 repository PNGs totalled 15,313,994 bytes; lossless PNG retained 15,010,083 bytes and lossless WebP produced 7,874,400 bytes (48.58% reduction). Every decoded RGBA pair matched in this corpus. Palette PNG at quality 95 is smaller but lossy and remains explicit. The maintained example:images entry writes source-bound PNG/WebP/SVG-size comparisons only under ignored .cache/render/raster-comparison. Published source closures are not rewritten to make comparison pass.

Validation: typecheck, 82 unit tests, 38 two-worker browser controls and full REUSE passed locally. Controls cover exact pixels/dimensions/alpha, codec opt-in, invalid/corrupt/foreign formats, output growth, bypass, real region hashes and raster MIME selection. CI also runs the maintained cases and executes native WebP encoding from a fresh Git-installed consumer. README/Org and third-party notices document tradeoffs and scope. Version/release and Cedar pins are unchanged pending review.

Final acceptance on e38c868: Linux/macOS renderer CI run 42026215730 passed, including 82 unit tests, 38 browser controls, six maintained example tests, all exports, the 38-image native format comparison and native WebP encoding in a fresh Bun Git consumer. Both REUSE checks passed; local full REUSE covers 734 files. PNG foreign-format/bypass controls passed after the final input-validation change. PR remains open for review; no release or downstream pin was changed.

@GTrunSec
GTrunSec merged commit 6f3113e into main Nov 5, 2026
4 checks passed
@GTrunSec
GTrunSec deleted the feat/render-image-compression branch November 5, 2026 12:25
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