Skip to content

fix: serve WebP by default, order formats, keep PNG transparency - #9

Merged
lxsmnsyc merged 1 commit into
mainfrom
image-format-defaults
Sep 13, 2026
Merged

fix: serve WebP by default, order formats, keep PNG transparency#9
lxsmnsyc merged 1 commit into
mainfrom
image-format-defaults

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Summary

Fixes the default output, which made every browser download PNG, and picks
formats per image so transparent images keep their transparency.

Changes

  • The default output is now WebP and JPEG. The old default was PNG, JPEG and
    WebP, in that order. The first source was PNG, every browser reads PNG, so
    every browser downloaded the largest format and WebP was never used.
  • Formats are now offered in a fixed order: AVIF, WebP, TIFF, JPEG, PNG. The
    order in output no longer matters.
  • The img falls back to the last format, which is JPEG or PNG. Every browser
    reads both. The old fallback under the default was WebP.
  • TIFF sorts before JPEG. Only Safari reads TIFF, so it must never be the
    fallback.
  • A transparent image gets PNG in place of JPEG. JPEG has no transparency, and
    sharp painted the transparent pixels black.
  • An opaque image drops PNG when JPEG is also listed, since JPEG is far smaller
    for photos. Listing PNG without JPEG keeps it.
  • getImageData now reports whether an image is transparent. It checks the
    pixels only when the image has an alpha channel, because many PNGs have one
    with every pixel opaque.
  • The transformer module and the fallback source both pick formats per image.

How it was tested

  • pnpm test runs 164 tests across both projects and they pass. 12 are new.
  • Plugin tests confirm the default output lists WebP before JPEG with no PNG,
    and that a config of PNG, JPEG, WebP and AVIF is offered as AVIF, WebP, JPEG.
  • A plugin test confirms a half transparent image gets WebP and PNG, no JPEG,
    and falls back to PNG.
  • A plugin test confirms an image with an alpha channel but only opaque pixels
    is treated as opaque.
  • Unit tests cover the format order, the TIFF position, dropping PNG for opaque
    images, keeping PNG when it is the only broad format, and swapping JPEG for
    PNG on transparent images.
  • Transformer tests confirm transparency detection for a see-through image and
    for an alpha channel with only opaque pixels.
  • pnpm build succeeds.
  • tsc --noEmit reports one pre-existing error in src/vite/fs.ts, unrelated to
    this change.

🤖 Generated with Claude Code

- Default output is now WebP and JPEG. The old default listed PNG first, so every browser downloaded PNG.
- Formats are offered smallest first, whatever order the config lists them in. The img falls back to JPEG or PNG.
- A transparent image gets PNG in place of JPEG, which painted its transparent pixels black.
- An opaque image drops PNG when JPEG is also listed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/image@9

commit: 626f6bc

@lxsmnsyc
lxsmnsyc merged commit 3b00d0b into main Sep 13, 2026
5 checks passed
@lxsmnsyc
lxsmnsyc deleted the image-format-defaults branch September 13, 2026 15:10
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