Code Monkey home page Code Monkey logo

node-pngquant-native's Introduction

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

  • option.speed

    Speed/quality trade-off from 1 (brute-force) to 11 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default. Speed 11 disables dithering and lowers compression level.

    var opt = {
        speed: 11
    }
  • option.quality = [min, max]

    min and max are numbers in range 0 (worst) to 100 (perfect), similar to JPEG. pngquant will use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved (if outputting to stdin, 24-bit original will be output) and pngquant will exit with status code 99.

    var opt = {
        quality: [40, 60]
    }
  • option.iebug

    Workaround for IE6, which only displays fully opaque pixels. pngquant will make almost-opaque pixels fully opaque and will avoid creating new transparent colors.

    var opt = {
        iebug: true
    }

ChangeLog

1.0.5

  • support node 8.x on MacOS

node-pngquant-native's People

Contributors

oxund avatar 2betop avatar iamelevich avatar daguej avatar wshxbqq avatar

Watchers

James Cloos avatar

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.