Skip to content

fix: preserve transparent RGB in quality 100 WebP - #281

Open
yeagoo wants to merge 2 commits into
VERT-sh:mainfrom
yeagoo:fix/webp-lossless-pixels
Open

fix: preserve transparent RGB in quality 100 WebP#281
yeagoo wants to merge 2 commits into
VERT-sh:mainfrom
yeagoo:fix/webp-lossless-pixels

Conversation

@yeagoo

@yeagoo yeagoo commented Sep 7, 2026

Copy link
Copy Markdown

libwebp can discard RGB channels beneath fully transparent pixels even when lossless coding is selected. For quality 100, set webp:exact=true so the decoded RGBA buffer is preserved, including invisible channel values. Leave the lossy encoder default unchanged.

This can make transparent images larger without changing their displayed appearance. It is therefore a lossless-output policy choice, isolated for maintainer review.

Scope: inputs routed through magickConvert, such as PNG → WebP. The existing GIF/WebP → GIF/WebP collection branch bypasses this helper (even for a single-frame WebP) and is not changed or covered by this fix.

Validation

PNG fixtures contain hidden red RGB at alpha 0 as well as partial and opaque alpha. Both metadata settings must preserve every decoded channel at quality 100; quality 80 must leave the webp:exact default untouched.

  • bun run test: 8 passed, including five shared behavior tests.
  • The defect-focused tests fail against the unchanged upstream conversion function (2 failing tests before this fix).
  • bun run build: passed with a local .env based on .env.example.
  • ESLint and Prettier: changed files pass.
  • bun run check: the same 7 pre-existing missing Node type errors as upstream; no additional errors. Full-repository lint has existing failures outside this change; changed files pass.

Patch structure

This branch is based on upstream cc7b5a54d5e9c797b377db47b9bdfbb561707783 and includes shared test harness commit c69e961, which moves the existing magickConvert function unchanged into a utility imported by the worker. Tests invoke that exact production function with the installed WASM. No new package dependency is introduced.

Each repair branch can be reviewed independently. After the shared harness lands, the remaining branches will need rebasing onto upstream main to resolve overlapping edits in magick-convert.ts.

Shares the behavior-preserving test harness with #275.

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