lovell / sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
https://sharp.pixelplumbing.com
Apache License 2.0
28.97k stars 1.29k forks source link

WebAssembly / CloudFlare workers support #2863

Closed antony closed 3 years ago

antony commented 3 years ago

What are you trying to achieve?

We'd love to deploy this on CloudFlare workers. As of early this year, libvips is now compiled for that target, so as I understand it, the remaining step is to compile sharp as WebAssembly.

Libvips issue is here https://github.com/libvips/libvips/issues/192

Have you searched for similar feature requests?

Yes - There is https://github.com/lovell/sharp/issues/1476 but it was closed and locked prior to the libvips changes.

What would you expect the API to look like?

I'm not at all familiar with WebAssembly, I'm afraid.

What alternatives have you considered?

Not using cloudflare workers

lovell commented 3 years ago

Please see https://github.com/kleisauke/wasm-vips/issues/2

okikio commented 2 years ago

wasm-vips is now a thing, so, is it possible to have a wasm version of sharp?

eli-front commented 1 year ago

Any updates here?

hadnet commented 1 year ago

It would be great if this package could work on CFW.

nilansaha commented 1 year ago

Nothing yet it seems. I coded up an image processing tool and then realized this does not work in Cloudflare workers

peterhirn commented 11 months ago

wasm-vips is now a thing, so, is it possible to have a wasm version of sharp?

Unfortunately wasm-vips will not be able to run on Cloudflare in the foreseeable future, see https://github.com/kleisauke/wasm-vips/issues/2#issuecomment-1187416552

Alternatives

lovell commented 10 months ago

Experimental support for WebAssembly environments will be arriving in v0.33.0 - please see https://github.com/lovell/sharp/issues/3336 - however Cloudflare Workers does not currently support threading or the Web Workers API so you'll need to ask Cloudflare about this lack of support if you need to use their services.

ThatGuySam commented 10 months ago

Experimental support for WebAssembly environments will be arriving in v0.33.0 - please see #3336 - however Cloudflare Workers does not currently support threading or the Web Workers API so you'll need to ask Cloudflare about this lack of support if you need to use their services.

@lovell Is there any kind of Single-Threaded mode for Sharp?

Even a dramatically slower option could still be useful for processing ultra-small images such as 100x100 thumbnails, Favicons, 50x50 Profile Pictures, etc...

lovell commented 10 months ago

@ThatGuySam Threading is fairly fundamental to libvips as well as an increasing number of the dependencies it relies on for image codecs. From what I can tell, Cloudflare Workers appears to be more suitable for tasks that are I/O bound rather than CPU bound. If performance isn't of concern then perhaps try jimp.