oxUnd / node-pngquant-native

A pngquant addon of node
47 stars 13 forks source link

node-pngquant-native

NPM version

node-pngquant-native is an addon of node, support node version v0.8.0 to latest, It compress a buffer of .png image, so can't call other processes.

install

npm install -g node-pngquant-native

make

if install fail for you. download the source install it.

  1. clone source code

    $ git clone https://github.com/xiangshouding/node-pngquant-native.git
  2. invoke npm install -g .

    $ cd node-pngquant-native
    $ npm install -g .

require

use


var pngquant = require('node-pngquant-native');

fs.readFile('./alphatest.png', function (err, buffer) {
  if (err) throw err;
  var resBuffer = pngquant.compress(buffer, {
    "speed": 1 //1 ~ 11
  });

  fs.writeFile('./alphatest_out.png', resBuffer, {
      flags: 'wb'
  }, function(err){});
});

Api

pngquant.compress(buffer, option)

var pngquant = require('node-pngquant-native')
var option = {
    speed: 11
    //...    
}

var resBuffer = pngquant.compress(buffer, option);

option

ChangeLog

1.0.5