fix: serve WebP by default, order formats, keep PNG transparency - #9
Merged
Conversation
- 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>
commit: |
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.
Summary
Fixes the default output, which made every browser download PNG, and picks
formats per image so transparent images keep their transparency.
Changes
outputis now WebP and JPEG. The old default was PNG, JPEG andWebP, in that order. The first
sourcewas PNG, every browser reads PNG, soevery browser downloaded the largest format and WebP was never used.
order in
outputno longer matters.imgfalls back to the last format, which is JPEG or PNG. Every browserreads both. The old fallback under the default was WebP.
fallback.
sharp painted the transparent pixels black.
for photos. Listing PNG without JPEG keeps it.
getImageDatanow reports whether an image is transparent. It checks thepixels only when the image has an alpha channel, because many PNGs have one
with every pixel opaque.
How it was tested
pnpm testruns 164 tests across both projects and they pass. 12 are new.and that a config of PNG, JPEG, WebP and AVIF is offered as AVIF, WebP, JPEG.
and falls back to PNG.
is treated as opaque.
images, keeping PNG when it is the only broad format, and swapping JPEG for
PNG on transparent images.
for an alpha channel with only opaque pixels.
pnpm buildsucceeds.tsc --noEmitreports one pre-existing error insrc/vite/fs.ts, unrelated tothis change.
🤖 Generated with Claude Code