Search code examples
webassemblyvips

How do you resample upscale an image using wasm-vips?


wasm-vips is a browser/node wrapper for libvips

Goals:

Using wasm-vips

  1. Upscale image using interpolator such as lanzcos3 or nohalo
  2. In the upscale method pass in a buffer instead of reading the image from a file

Example reading an image

 const vips = await Vips();

    let im = vips.Image.newFromFile('in.jpg');

But I do not know the function and properties I need to use to resample my image to 2017x2017

It looks like I need to use vips.affine as shown in the vips docs. https://www.libvips.org/API/current/libvips-resample.html#vips-affine

The wasm-vips has the affine method im.affine() but I don't know how to specify the interpolater such as lanzcos3. I also want to pass in a uint8array instead of reading an image from a file directly.

Thanks, Dan


Solution

  • I would guess:

    im.resize(2017 / im.width, {kernel: 'lanczos3'})
    

    And I'd look at newFromMemory to read from a uint8 array. Ask on the wasm-vips issue tracker:

    https://github.com/kleisauke/wasm-vips

    (was a comment, made into an answer on request)