denoland / wanted_modules

Is there a missing deno module that is preventing you from building something? Let us know here.
https://deno.land/x
46 stars 2 forks source link

Sharp #23

Open oscarotero opened 2 years ago

oscarotero commented 2 years ago

I miss a good image processing library like sharp: https://github.com/lovell/sharp/issues/2583

There's an alternative based on imagick (https://github.com/lumeland/imagemagick-deno) but it's a bit slow.

Tricked-dev commented 2 years ago

https://deno.land/x/imagescript although quite low level

oscarotero commented 2 years ago

Yes, I tested it but it's very limited. For resizing it only support nearest neighbor interpolation, that produces low quality results (pixelated images).

The v2 looks promising but it will take a while to be released.

andre4ik3 commented 2 years ago

See also: https://github.com/lovell/sharp/issues/1476, https://github.com/libvips/libvips/issues/192, https://github.com/kleisauke/wasm-vips/issues/1

TLDR: Sharp uses libvips which uses a lot of native stuff. It's been ported to WebAssembly using Emscripten but not yet stable. I think the best approach would be for Sharp to be compatible with WebAssembly so that it can be used anywhere WASM is supported, not just (but including) Deno, also since the FFI API is not yet stable and would require downloading platform & arch-specific binaries which can get messy...

oscarotero commented 2 years ago

That's interesting!

FYI, I'm using https://github.com/lumeland/imagemagick-deno, a port to make https://github.com/dlemstra/magick-wasm working with Deno.

birkskyum commented 1 year ago

As reported in here, this is the current installation experience:

I manually installed Sharp as suggested above, but I am getting the following error on Mac M1. Looks like I will park Deno - Sharp experiments for now.

error: Uncaught Error: Something went wrong installing the "sharp" module

Unable to find napi_register_module_v1 symbol in /Users/xx/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/build/Release/sharp-darwin-arm64v8.node

Possible solutions:

  • Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
  • Install for the current darwin-arm64v8 runtime: "npm install --platform=darwin --arch=arm64v8 sharp"
  • Consult the installation documentation: https://sharp.pixelplumbing.com/install at Object. (file:///Users/xx/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/sharp.js:37:9) at Object. (file:///Users/xx/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/sharp.js:40:4) at Module._compile (node:module:718:36) at Object.Module._extensions..js (node:module:737:12) at Module.load (node:module:652:34) at Function.Module._load (node:module:534:16) at Module.require (node:module:671:23) at require (node:module:771:20) at Object. (file:///Users/xx/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/constructor.js:11:1) at Object. (file:///Users/xx/Library/Caches/deno/npm/registry.npmjs.org/sharp/0.32.4/lib/constructor.js:441:4)
lovell commented 7 months ago

For those who hadn't seen, Deno (with --allow-ffi) support is provided by sharp from v0.33.0 onwards. Every release is now tested against the latest Deno version at that point in time on Linux, macOS and Windows e.g. https://github.com/lovell/sharp/actions/runs/7501251989

oscarotero commented 7 months ago

Thanks, @lovell. The package works great on Deno!

There's still a minor issue but seems a bug on N-API implementation by Deno: https://github.com/denoland/deno/issues/21686

marcatatem commented 6 months ago

There's still a minor issue but seems a bug on N-API implementation by Deno: denoland/deno#21686

Actually not so minor as you're stuck with v1.38.5 if using Sharp .toBuffer() method :)