Skip to content

Conversation

@blt-r
Copy link
Contributor

@blt-r blt-r commented Feb 3, 2026

closes #15242


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 7a7d2fa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/enhanced-img Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@teemingc teemingc changed the title enhanced-img: use jpg as a fallback format fix: use jpg as a fallback format Feb 3, 2026
Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • this would break transparency. if you have an avif or webp with transparency you'd lose that converting to jpg
  • if the original image is a png or gif image, the intention was that you'd serve the original image as a fallback

@blt-r
Copy link
Contributor Author

blt-r commented Feb 4, 2026

We can check metadata.hasAlpha? The only downside I can see to that, is that we'll always need to await metadata() and now we only do that when imgWidth is not passed. It is passed when user sets manually width prop, which is rare anyway. Even if it isn't, I don't think awaiting the metadata is much of a performance hit

@benmccann
Copy link
Member

The only downside I can see to that, is that we'll always need to await metadata() and now we only do that when imgWidth is not passed.

We could skip doing that if the extension is .jpg or .jpeg, which it will be quite frequently. In that case, there's no need to check the metadata because we know the image cannot be animated or transparent and so we will need to stick to the jpg format

@blt-r
Copy link
Contributor Author

blt-r commented Feb 5, 2026

We could skip doing that if the extension is .jpg or .jpeg

I don't think that's necessary, I've just looked at the source code and vite-imagetools caches the metadata object and later uses it itself to clamp the sizes to the intrinsic size of the image, unless allowUpscale is passed. So if we don't read the metadata it will be read later anyways.

@benmccann
Copy link
Member

later uses it itself to clamp the sizes to the intrinsic size of the image, unless allowUpscale is passed. So if we don't read the metadata it will be read later anyways.

It looks like that's only true if w or h are manually specified

@svelte-docs-bot
Copy link

@blt-r
Copy link
Contributor Author

blt-r commented Feb 6, 2026

w is always manually specified, in the defaultDirectives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enahnced-img: png as a fallback format doesn't make sense.

3 participants