GithubHelp home page GithubHelp logo

node-vips's Introduction

Experimental node.js binding for libvips built on ffi

Unmaintained This package depends on npm packages which are now unmaintained. It needs updating to (perhaps?) use ffi-napi.

Status

It's mostly complete, it seems stable, and it passes the tests suite with no errors or leaks. It can reliably thumbnail 10,000 jpeg images in constant memory and without falling over. Probably.

Example

var vips = require('vips');

var image = vips.Image.newFromFile(process.argv[2]);
image = image.crop(100, 100, image.width - 200, image.height - 200);

image = image.reduce(1.0 / 0.9, 1.0 / 0.9, {kernel: 'linear'});

var mask = vips.Image.newFromArray(
  [[-1,  -1, -1], 
   [-1,  16, -1], 
   [-1,  -1, -1]], 8);
image = image.conv(mask, {precision: 'integer'});

image.writeToFile(process.argv[3]);

async

node-vips is synchronous by default, but you can call any operation with the special async option, for example:

image.writeToFile('file.jpg', {
  Q: 90,
  async: (err, result) => {
    if (err) {
      throw err;
    }
  }
});

image.max({
  async: (err, result) => {
    if (err) {
      throw err;
    }

    console.log('maximum value in image is ' + result);
  }
});

Most operations are instant -- it only makes sense to use async for things which will trigger a pixel loop.

References

https://github.com/node-ffi/node-ffi

https://github.com/TooTallNate/ref

https://github.com/TooTallNate/ref-array

https://github.com/TooTallNate/ref-struct

https://github.com/TooTallNate/weak

https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial

Actions

Install everything

npm install 

Run the tests

npm test

Run a single test with the GC enabled

./node_modules/.bin/mocha --expose-gc test/unit/image.js 

Regenerate convenience wrappers

vips = require('vips');
vips.generateWrappers();

and copy output to lib/autogen.js.

see example/gen-wrapper.js.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.