Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imagemin-advpng

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imagemin-advpng - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc