pngquant
Version:
The pngquant utility as a readable/writable stream
56 lines (39 loc) • 1.61 kB
Markdown
//badge.fury.io/js/pngquant.svg)](http://badge.fury.io/js/pngquant)
[](https://travis-ci.org/papandreou/node-pngquant)
[](https://coveralls.io/r/papandreou/node-pngquant)
[](https://david-dm.org/papandreou/node-pngquant)
The pngquant command line utility as a readable/writable stream.
The constructor optionally takes an array of command line options for
the `pngquant` binary (defaults to `[256]`):
```javascript
import PngQuant from 'pngquant';
const myPngQuanter = new PngQuant([192, '--quality', '60-80', '--nofs', '-']);
sourceStream.pipe(myPngQuanter).pipe(destinationStream);
```
PngQuant as a web service (sends back a png with the number of colors
quantized to 128):
```javascript
import PngQuant from 'pngquant';
import http from 'http';
http
.createServer(function (req, res) {
if (req.headers['content-type'] === 'image/png') {
res.writeHead(200, { 'Content-Type': 'image/png' });
req.pipe(new PngQuant([128])).pipe(res);
} else {
res.writeHead(400);
res.end('Feed me a PNG!');
}
})
.listen(1337);
```
Make sure you have node.js and npm installed, and that the `pngquant` binary is in your PATH, then run:
```
npm install pngquant
```
See the [changelog](CHANGELOG.md).
3-clause BSD license -- see the `LICENSE` file for details.
[![NPM version](https: