imagemin-advpng
Advanced tools
Comparing version 3.1.0 to 4.0.0
69
index.js
'use strict'; | ||
const execBuffer = require('exec-buffer'); | ||
const advpng = require('advpng-bin'); | ||
const isPng = require('is-png'); | ||
const tempfile = require('tempfile'); | ||
var advpng = require('advpng-bin'); | ||
var ExecBuffer = require('exec-buffer'); | ||
var isPng = require('is-png'); | ||
var through = require('through2'); | ||
module.exports = opts => buf => { | ||
opts = Object.assign({optimizationLevel: 3}, opts); | ||
module.exports = function (opts) { | ||
opts = opts || {}; | ||
if (!Buffer.isBuffer(buf)) { | ||
return Promise.reject(new TypeError(`Expected a \`Buffer\`, got \`${typeof buf}\``)); | ||
} | ||
return through.ctor({objectMode: true}, function (file, enc, cb) { | ||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
if (!isPng(buf)) { | ||
return Promise.resolve(buf); | ||
} | ||
if (file.isStream()) { | ||
cb(new Error('Streaming is not supported')); | ||
return; | ||
} | ||
const args = ['--recompress', '-q']; | ||
const tmp = tempfile(); | ||
if (!isPng(file.contents)) { | ||
cb(null, file); | ||
return; | ||
} | ||
if (typeof opts.optimizationLevel === 'number') { | ||
args.push(`-${opts.optimizationLevel}`); | ||
} | ||
var execBuffer = new ExecBuffer(); | ||
var args = ['--recompress', '-q']; | ||
var optimizationLevel = opts.optimizationLevel || 3; | ||
args.push(execBuffer.input); | ||
if (typeof optimizationLevel === 'number') { | ||
args.push('-' + optimizationLevel); | ||
} | ||
execBuffer | ||
.dest(execBuffer.src()) | ||
.use(advpng, args.concat([execBuffer.src()])) | ||
.run(file.contents, function (err, buf) { | ||
if (err) { | ||
err.fileName = file.path; | ||
cb(err); | ||
return; | ||
} | ||
if (buf.length < file.contents.length) { | ||
file.contents = buf; | ||
} | ||
cb(null, file); | ||
}); | ||
return execBuffer({ | ||
input: buf, | ||
bin: advpng, | ||
args, | ||
inputPath: tmp, | ||
outputPath: tmp | ||
}).catch(err => { | ||
err.message = err.stderr || err.message; | ||
throw err; | ||
}); | ||
}; |
{ | ||
"name": "imagemin-advpng", | ||
"version": "3.1.0", | ||
"description": "advpng imagemin plugin", | ||
"license": "MIT", | ||
"repository": "imagemin/imagemin-advpng", | ||
"author": { | ||
"name": "Kevin Mårtensson", | ||
"email": "kevinmartensson@gmail.com", | ||
"url": "https://github.com/kevva" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"advpng", | ||
"compress", | ||
"gulpplugin", | ||
"image", | ||
"imageminplugin", | ||
"img", | ||
"minify", | ||
"optimize", | ||
"png" | ||
], | ||
"dependencies": { | ||
"advpng-bin": "^3.0.0", | ||
"exec-buffer": "^2.0.1", | ||
"is-png": "^1.0.0", | ||
"through2": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"vinyl": "^1.1.0", | ||
"vinyl-file": "^1.1.0", | ||
"xo": "*" | ||
} | ||
"name": "imagemin-advpng", | ||
"version": "4.0.0", | ||
"description": "AdvPNG imagemin plugin", | ||
"license": "MIT", | ||
"repository": "imagemin/imagemin-advpng", | ||
"author": { | ||
"name": "Kevin Mårtensson", | ||
"email": "kevinmartensson@gmail.com", | ||
"url": "github.com/kevva" | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
{ | ||
"name": "Shinnosuke Watanabe", | ||
"url": "github.com/shinnn" | ||
} | ||
], | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"advpng", | ||
"compress", | ||
"gulpplugin", | ||
"image", | ||
"imageminplugin", | ||
"img", | ||
"minify", | ||
"optimize", | ||
"png" | ||
], | ||
"dependencies": { | ||
"advpng-bin": "^3.0.0", | ||
"exec-buffer": "^3.1.0", | ||
"is-png": "^1.0.0", | ||
"tempfile": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # imagemin-advpng [![Build Status](http://img.shields.io/travis/imagemin/imagemin-advpng.svg?style=flat)](https://travis-ci.org/imagemin/imagemin-advpng) [![Build status](https://ci.appveyor.com/api/projects/status/8vw4a6jtvhao3jev?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/imagemin-advpng) | ||
``` | ||
$ npm install --save imagemin-advpng | ||
$ npm install imagemin-advpng | ||
``` | ||
@@ -17,33 +17,22 @@ | ||
```js | ||
var Imagemin = require('imagemin'); | ||
var imageminAdvpng = require('imagemin-advpng'); | ||
const imagemin = require('imagemin'); | ||
const imageminAdvpng = require('imagemin-advpng'); | ||
new Imagemin() | ||
.src('images/*.png') | ||
.dest('build/images') | ||
.use(imageminAdvpng({optimizationLevel: 4})) | ||
.run(); | ||
imagemin(['images/*.png'], 'build/images', {use: [imageminAdvpng()]}).then(() => { | ||
console.log('Images optimized'); | ||
}); | ||
``` | ||
You can also use this plugin with [gulp](http://gulpjs.com): | ||
```js | ||
var gulp = require('gulp'); | ||
var imageminAdvpng = require('imagemin-advpng'); | ||
## API | ||
gulp.task('default', function () { | ||
return gulp.src('images/*.png') | ||
.pipe(imageminAdvpng({optimizationLevel: 4})()) | ||
.pipe(gulp.dest('build/images')); | ||
}); | ||
``` | ||
### imageminAdvpng([options])(buffer) | ||
#### options | ||
## API | ||
Type: `Object` | ||
### imageminAdvpng(options) | ||
##### optimizationLevel | ||
#### options.optimizationLevel | ||
Type: `number` | ||
Type: `number`<br> | ||
Default: `3` | ||
@@ -55,11 +44,17 @@ | ||
`0` Don't compress | ||
`1` Compress fast (zlib) | ||
`2` Compress normal (7z) | ||
`3` Compress extra (7z) | ||
`0` Don't compress<br> | ||
`1` Compress fast (zlib)<br> | ||
`2` Compress normal (7z)<br> | ||
`3` Compress extra (7z)<br> | ||
`4` Compress extreme (zopfli) | ||
#### buffer | ||
Type: `Buffer` | ||
Buffer to optimize. | ||
## License | ||
MIT © [imagemin](https://github.com/imagemin) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
2
0
3834
30
58
+ Addedtempfile@^2.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
- Removedexec-buffer@2.0.1(transitive)
Updatedexec-buffer@^3.1.0