Repository navigation
Compress rendered images with Sharp and compare PNG/WebP outputs - #8
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.