Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WebP embedded in SVG #258

Open
privatenumber opened this issue Nov 6, 2024 · 2 comments
Open

Support WebP embedded in SVG #258

privatenumber opened this issue Nov 6, 2024 · 2 comments

Comments

@privatenumber
Copy link

Feature request

What are you trying to achieve?

Embedding WebP in SVGs and converting that SVG to PNG or WebP

When you searched for similar feature requests, what did you find that might be related?

There are tests supporting PNGs embedding in SVGs:
https://github.com/lovell/sharp/blob/1533bf995acda779313fc178d2b9d46791349961/test/unit/svg.js#L116

What would you expect the API to look like?

No API change.

What alternatives have you considered?

Please provide sample image(s) that help explain this feature

N/A

@lovell
Copy link
Owner

lovell commented Nov 6, 2024

Hello, as you've probably seen, the SVG2 spec requires support for JPEG and PNG image formats:

https://www.w3.org/TR/SVG2/conform.html#ConformingSVGViewers

"The viewer must support JPEG and PNG image formats"

Support for formats beyond these is optional, and there was some previous discussion about these within sharp at #226

I'm going to move this issue to the lovell/sharp-libvips repo for future possible consideration in the native prebuilt binaries. The WebAssembly build of sharp already does support WebP (and, I think, GIF) within SVG, so there's internal inconsistency within sharp.

In the meantime, sharp supports the use of a globally-installed libvips, which if compiled with support for librsvg that is compiled with support for WebP.

https://sharp.pixelplumbing.com/install#custom-libvips
https://sharp.pixelplumbing.com/install#building-from-source

Finally, thank you very much for all your work on tsx, I've found myself using it many times (e.g. to deal with ESM-related problems) and it's always been a pleasure.

@lovell lovell transferred this issue from lovell/sharp Nov 6, 2024
@papag00se
Copy link

Two legends! tsx and sharp! Thank you to you both!

This is just an FYI. Maybe not too helpful in the context of this issue, but happy to provide more details if it is interesting.

We use sharp in https://handle.me to convert our dynamically-built SVGs into NFT images on IPFS. Our users sometimes upload WebP images as part of this process. Switching to the WASM version worked great, BUT, the SVG paths that have CSS filter: drop-shadow renders differently through the WASM build. The color is significantly off as well as the blur effect. When rendered through the normal sharp build it is spot on, but then no WebP.

So in our case, we'd love to see WebP in the main npm build :)

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

No branches or pull requests

3 participants