imagemin-pngquant
Advanced tools
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) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
3
0
4880
46
89
+ Addedexec-buffer@^3.0.0
+ Addedcross-spawn@5.1.0(transitive)
+ Addedexec-buffer@3.2.0(transitive)
+ Addedexeca@0.7.0(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addednpm-run-path@2.0.2(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedpath-key@2.0.1(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedstrip-eof@1.0.0(transitive)
+ Addedtemp-dir@1.0.0(transitive)
+ Addedtempfile@2.0.0(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyallist@2.1.2(transitive)
- Removedthrough2@^2.0.0