[web.worker] optimize Open Graph PNG size #118

Merged
eleith merged 1 commits from fix/112-optimize-opengraph-images into main 2026-10-16 23:31:00 +00:00

Summary

Closes #112.

Reduce final Open Graph image sizes with the existing Sharp dependency, after Takumi renders the card:

  • Encode a palette PNG with quality: 90, effort: 7, and compressionLevel: 9.
  • Keep the original buffer if the optimized PNG is not smaller.
  • Preserve dimensions, transparency support, paths, asset records, and image/png MIME types.
  • Apply the same transform in publish and preview; no new dependencies, processes, services, or request-time work.
  • Keep success logging in the existing transform runner; no additional per-card log.
  • Include a patch changeset.

Impact and tradeoffs

Same-input benchmarks on three existing local demo cards using these exact settings:

Sample Original PNG Optimized PNG Reduction Extra encoding time
Book 392,557 bytes 119,035 bytes 70% ~308 ms
Film 350,892 bytes 93,538 bytes 73% ~319 ms
Code snippet 34,225 bytes 15,614 bytes 54% ~83 ms

These are illustrative local samples, not a whole-archive performance guarantee. Palette encoding is lossy: reducing the available colors can affect photographs, gradients, shadows, and antialiased edges. The owner rendered additional previews and reported acceptable visual quality. Existing files are only changed when regenerated; this PR does not trigger a bulk republish.

Verification

  • Worker ESLint: passed.
  • Worker TypeScript build: passed.
  • Full worker suite: 45 files, 277 tests passed with coverage.
  • Changed Open Graph transform: 100% statements, branches, functions, and lines covered.
  • Real Sharp tests cover a smaller valid PNG, dimensions and semitransparency, keeping a smaller original, encoding-error propagation without writing an output, and prior-asset forwarding.
  • git diff --check: passed.

Verification used installed project executables directly because pnpm attempted to read an npm config denied by the session sandbox. No dependencies were installed or changed.

Review scope

Only the worker transform, its tests, and changeset are included. Existing local demo archive edits and generated images are excluded.

## Summary Closes #112. Reduce final Open Graph image sizes with the existing Sharp dependency, after Takumi renders the card: - Encode a palette PNG with `quality: 90`, `effort: 7`, and `compressionLevel: 9`. - Keep the original buffer if the optimized PNG is not smaller. - Preserve dimensions, transparency support, paths, asset records, and `image/png` MIME types. - Apply the same transform in publish and preview; no new dependencies, processes, services, or request-time work. - Keep success logging in the existing transform runner; no additional per-card log. - Include a patch changeset. ## Impact and tradeoffs Same-input benchmarks on three existing local demo cards using these exact settings: | Sample | Original PNG | Optimized PNG | Reduction | Extra encoding time | | --- | ---: | ---: | ---: | ---: | | Book | 392,557 bytes | 119,035 bytes | 70% | ~308 ms | | Film | 350,892 bytes | 93,538 bytes | 73% | ~319 ms | | Code snippet | 34,225 bytes | 15,614 bytes | 54% | ~83 ms | These are illustrative local samples, not a whole-archive performance guarantee. Palette encoding is lossy: reducing the available colors can affect photographs, gradients, shadows, and antialiased edges. The owner rendered additional previews and reported acceptable visual quality. Existing files are only changed when regenerated; this PR does not trigger a bulk republish. ## Verification - Worker ESLint: passed. - Worker TypeScript build: passed. - Full worker suite: **45 files, 277 tests passed** with coverage. - Changed Open Graph transform: **100% statements, branches, functions, and lines covered**. - Real Sharp tests cover a smaller valid PNG, dimensions and semitransparency, keeping a smaller original, encoding-error propagation without writing an output, and prior-asset forwarding. - `git diff --check`: passed. Verification used installed project executables directly because pnpm attempted to read an npm config denied by the session sandbox. No dependencies were installed or changed. ## Review scope Only the worker transform, its tests, and changeset are included. Existing local demo archive edits and generated images are excluded.
eleith added 1 commit 2026-10-16 23:30:17 +00:00
[web.worker] optimize Open Graph PNG encoding
ci/woodpecker/pr/web-worker Pipeline was successful
ci/woodpecker/push/web-worker Pipeline was successful
ac811d618b
eleith force-pushed fix/112-optimize-opengraph-images from b1209334f1 to ac811d618b 2026-10-16 23:30:17 +00:00 Compare
eleith merged commit ac811d618b into main 2026-10-16 23:31:00 +00:00
eleith deleted branch fix/112-optimize-opengraph-images 2026-10-16 23:31:00 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: eleith/luzzle#118