Socket
Socket
Sign inDemoInstall

imagemin-pngquant

Package Overview
Dependencies
288
Maintainers
3
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.2.2 to 5.0.0

122

index.js
'use strict';
var spawn = require('child_process').spawn;
var isPng = require('is-png');
var pngquant = require('pngquant-bin');
var through = require('through2');
const execBuffer = require('exec-buffer');
const isPng = require('is-png');
const pngquant = require('pngquant-bin');
module.exports = function (opts) {
opts = opts || {};
module.exports = opts => buf => {
opts = Object.assign({}, opts);
return through.ctor({objectMode: true}, function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (!Buffer.isBuffer(buf)) {
return Promise.reject(new TypeError('Expected a buffer'));
}
if (file.isStream()) {
cb(new Error('Streaming is not supported'));
return;
}
if (!isPng(buf)) {
return Promise.resolve(buf);
}
if (!isPng(file.contents)) {
cb(null, file);
return;
}
const args = [
'--output', execBuffer.output,
execBuffer.input
];
var args = ['-'];
var ret = [];
var err = '';
var len = 0;
if (opts.floyd && typeof opts.floyd === 'number') {
args.push(`--floyd=${opts.floyd}`);
}
if (opts.floyd && typeof opts.floyd === 'number') {
args.push('--floyd=' + opts.floyd);
}
if (opts.floyd && typeof opts.floyd === 'boolean') {
args.push('--floyd');
}
if (opts.floyd && typeof opts.floyd === 'boolean') {
args.push('--floyd');
}
if (opts.nofs) {
args.push('--nofs');
}
if (opts.nofs) {
args.push('--nofs');
}
if (opts.posterize) {
args.push('--posterize', opts.posterize);
}
if (opts.posterize) {
args.push('--posterize', opts.posterize);
}
if (opts.quality) {
args.push('--quality', opts.quality);
}
if (opts.quality) {
args.push('--quality', opts.quality);
}
if (opts.speed) {
args.push('--speed', opts.speed);
}
if (opts.speed) {
args.push('--speed', opts.speed);
}
if (opts.verbose) {
args.push('--verbose');
}
if (opts.verbose) {
args.push('--verbose');
}
var cp = spawn(pngquant, args);
cp.stderr.setEncoding('utf8');
cp.stderr.on('data', function (data) {
err += data;
});
cp.stdout.on('data', function (data) {
ret.push(data);
len += data.length;
});
cp.on('error', function (err) {
err.fileName = file.path;
cb(err);
return;
});
cp.on('close', function (code) {
if (code && code !== 99) {
err = new Error(err);
err.fileName = file.path;
cb(err);
return;
}
if (len < file.contents.length) {
file.contents = Buffer.concat(ret, len);
}
cb(null, file);
});
cp.stdin.end(file.contents);
return execBuffer({
input: buf,
bin: pngquant,
args
}).catch(err => {
err.message = err.stderr || err.message;
throw err;
});
};
{
"name": "imagemin-pngquant",
"version": "4.2.2",
"version": "5.0.0",
"description": "pngquant imagemin plugin",

@@ -24,6 +24,6 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && ava test/test.js"
"test": "xo && ava"
},

@@ -35,3 +35,2 @@ "files": [

"compress",
"gulpplugin",
"image",

@@ -46,12 +45,14 @@ "imageminplugin",

"dependencies": {
"exec-buffer": "^3.0.0",
"is-png": "^1.0.0",
"pngquant-bin": "^3.0.0",
"through2": "^2.0.0"
"pngquant-bin": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"buffer-equals": "^1.0.3",
"vinyl-file": "^2.0.0",
"pify": "^2.3.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -16,33 +16,22 @@ # imagemin-pngquant [![Build Status](https://travis-ci.org/imagemin/imagemin-pngquant.svg?branch=master)](https://travis-ci.org/imagemin/imagemin-pngquant) [![Build status](https://ci.appveyor.com/api/projects/status/w60auppnbiwgu9gj?svg=true)](https://ci.appveyor.com/project/kevva/imagemin-pngquant)

```js
const Imagemin = require('imagemin');
const imagemin = require('imagemin');
const imageminPngquant = require('imagemin-pngquant');
const Imagemin()
.src('images/*.png')
.dest('build/images')
.use(imageminPngquant({quality: '65-80', speed: 4}))
.run();
imagemin(['images/*.png'], 'build/images', {use: [imageminPngquant()]}).then(() => {
console.log('Images optimized');
});
```
You can also use this plugin with [gulp](http://gulpjs.com):
```js
const gulp = require('gulp');
const imageminPngquant = require('imagemin-pngquant');
## API
gulp.task('default', () => {
return gulp.src('images/*.png')
.pipe(imageminPngquant({quality: '65-80', speed: 4})())
.pipe(gulp.dest('build/images'));
});
```
### imageminPngquant([options])(buffer)
Returns a promise for a buffer.
## API
#### options
### imageminPngquant(options)
##### floyd
#### options.floyd
Type: `number`, `boolean`
Type: `number`, `boolean`<br>
Default: `0.5`

@@ -52,5 +41,5 @@

#### options.nofs
##### nofs
Type: `boolean`
Type: `boolean`<br>
Default: `false`

@@ -60,15 +49,15 @@

#### options.posterize
##### posterize
Type: `number`
Reduce precision of the palette by number of bits. Use when the image will be
Reduce precision of the palette by number of bits. Use when the image will be
displayed on low-depth screens (e.g. 16-bit displays or compressed textures).
#### options.quality
##### quality
Type: `string`
Instructs pngquant to use the least amount of colors required to meet or exceed
the max quality. If conversion results in quality below the min quality the
Instructs pngquant to 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.

@@ -78,13 +67,13 @@

#### options.speed
##### speed
Type: `number`
Type: `number`<br>
Default: `3`
Speed/quality trade-off from `1` (brute-force) to `10` (fastest). Speed `10` has
Speed/quality trade-off from `1` (brute-force) to `10` (fastest). Speed `10` has
5% lower quality, but is 8 times faster than the default.
#### options.verbose
##### verbose
Type: `boolean`
Type: `boolean`<br>
Default: `false`

@@ -94,5 +83,11 @@

#### buffer
Type: `buffer`
Buffer to optimize.
## License
MIT © [imagemin](https://github.com/imagemin)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc