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

imagemin-mozjpeg

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imagemin-mozjpeg - npm Package Compare versions

Comparing version 5.1.0 to 6.0.0

174

index.js
'use strict';
const execBuffer = require('exec-buffer');
const isJpg = require('is-jpg');
const mozjpeg = require('mozjpeg');
var spawn = require('child_process').spawn;
var isJpg = require('is-jpg');
var mozjpeg = require('mozjpeg');
var through = require('through2');
module.exports = opts => buf => {
opts = Object.assign({}, opts);
module.exports = function (opts) {
opts = opts || {};
if (!Buffer.isBuffer(buf)) {
return Promise.reject(new TypeError('Expected a buffer'));
}
return through.ctor({objectMode: true}, function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (!isJpg(buf)) {
return Promise.resolve(buf);
}
if (file.isStream()) {
cb(new Error('Streaming is not supported'));
return;
}
const args = ['-outfile', execBuffer.output];
if (!isJpg(file.contents)) {
cb(null, file);
return;
}
if (typeof opts.quality !== 'undefined') {
args.push('-quality', opts.quality);
}
var args = [];
var err = '';
var ret = [];
var len = 0;
if (opts.progressive === false) {
args.push('-baseline');
}
if (typeof opts.quality !== 'undefined') {
args.push('-quality', opts.quality);
}
if (opts.targa) {
args.push('-targa');
}
if (opts.progressive === false) {
args.push('-baseline');
}
if (opts.revert) {
args.push('-revert');
}
if (opts.targa) {
args.push('-targa');
}
if (opts.fastcrush) {
args.push('-fastcrush');
}
if (opts.revert) {
args.push('-revert');
}
if (typeof opts.dcScanOpt !== 'undefined') {
args.push('-dc-scan-opt', opts.dcScanOpt);
}
if (opts.fastcrush) {
args.push('-fastcrush');
}
if (opts.notrellis) {
args.push('-notrellis');
}
if (typeof opts.dcScanOpt !== 'undefined') {
args.push('-dc-scan-opt', opts.dcScanOpt);
}
if (opts.notrellisDC) {
args.push('-notrellis-dc');
}
if (opts.notrellis) {
args.push('-notrellis');
}
if (opts.tune) {
args.push(`-tune-${opts.tune}`);
}
if (opts.notrellisDC) {
args.push('-notrellis-dc');
}
if (opts.noovershoot) {
args.push('-noovershoot');
}
if (opts.tune) {
args.push('-tune-' + opts.tune);
}
if (opts.arithmetic) {
args.push('-arithmetic');
}
if (opts.noovershoot) {
args.push('-noovershoot');
}
if (opts.dct) {
args.push('-dct', opts.dct);
}
if (opts.arithmetic) {
args.push('-arithmetic');
}
if (typeof opts.quantTable !== 'undefined') {
args.push('-quant-table', opts.quantTable);
}
if (opts.dct) {
args.push('-dct', opts.dct);
}
if (opts.smooth) {
args.push('-smooth', opts.smooth);
}
if (typeof opts.quantTable !== 'undefined') {
args.push('-quant-table', opts.quantTable);
}
if (opts.maxmemory) {
args.push('-maxmemory', opts.maxmemory);
}
if (opts.smooth) {
args.push('-smooth', opts.smooth);
}
args.push(execBuffer.input);
if (opts.maxmemory) {
args.push('-maxmemory', opts.maxmemory);
}
var cp = spawn(mozjpeg, 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) {
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.on('error', function (stdinErr) {
if (!err) {
err = stdinErr;
}
});
cp.stdin.end(file.contents);
return execBuffer({
input: buf,
bin: mozjpeg,
args
}).catch(err => {
err.message = err.stderr || err.message;
throw err;
});
};
{
"name": "imagemin-mozjpeg",
"version": "5.1.0",
"version": "6.0.0",
"description": "mozjpeg imagemin plugin",

@@ -10,9 +10,20 @@ "license": "MIT",

"email": "kevinmartensson@gmail.com",
"url": "https://github.com/kevva"
"url": "github.com/kevva"
},
"maintainers": [
{
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
{
"name": "Shinnosuke Watanabe",
"url": "github.com/shinnn"
}
],
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "node test/test.js"
"test": "xo && ava"
},

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

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

@@ -36,13 +46,15 @@ "imageminplugin",

"dependencies": {
"exec-buffer": "^3.0.0",
"is-jpg": "^1.0.0",
"mozjpeg": "^4.0.0",
"through2": "^0.6.1"
"mozjpeg": "^4.0.0"
},
"devDependencies": {
"ava": "^0.0.4",
"buffer-equal": "0.0.1",
"ava": "*",
"is-progressive": "^1.0.1",
"vinyl-file": "^1.1.0",
"vinyl-smallest-jpeg": "^1.0.0"
"pify": "^2.3.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -16,32 +16,21 @@ # imagemin-mozjpeg [![Build Status](https://travis-ci.org/imagemin/imagemin-mozjpeg.svg?branch=master)](https://travis-ci.org/imagemin/imagemin-mozjpeg) [![Build status](https://ci.appveyor.com/api/projects/status/uuh7yi48erf4ykyo?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/imagemin-mozjpeg)

```js
var Imagemin = require('imagemin');
var imageminMozjpeg = require('imagemin-mozjpeg');
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
new Imagemin()
.src('images/*.jpg')
.dest('build/images')
.use(imageminMozjpeg({quality: 80}))
.run();
imagemin(['images/*.jpg'], 'build/images', {use: [imageminMozjpeg()]}).then(() => {
console.log('Images optimized');
});
```
You can also use this plugin with [gulp](http://gulpjs.com):
```js
var gulp = require('gulp');
var imageminMozjpeg = require('imagemin-mozjpeg');
## API
gulp.task('default', function () {
return gulp.src('images/*.jpg')
.pipe(imageminMozjpeg({quality: 80})())
.pipe(gulp.dest('build/images'));
});
```
### imageminMozjpeg([options])(buffer)
Returns a promise for a buffer.
## API
#### options
### imageminMozjpeg(options)
##### quality
#### options.quality
Type: `number`

@@ -51,5 +40,5 @@

#### options.progressive
##### progressive
Type: `boolean`
Type: `boolean`<br>
Default: `true`

@@ -59,5 +48,5 @@

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

@@ -67,5 +56,5 @@

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

@@ -75,5 +64,5 @@

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

@@ -83,5 +72,5 @@

#### options.dcScanOpt
##### dcScanOpt
Type: `number`
Type: `number`<br>
Default: `1`

@@ -95,5 +84,5 @@

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

@@ -103,5 +92,5 @@

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

@@ -111,5 +100,5 @@

#### options.tune
##### tune
Type: `string`
Type: `string`<br>
Default: `hvs-psnr`

@@ -119,5 +108,5 @@

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

@@ -127,5 +116,5 @@

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

@@ -135,3 +124,3 @@

#### options.quantTable
##### quantTable

@@ -149,3 +138,3 @@ Type: `number`

#### options.smooth
##### smooth

@@ -156,3 +145,3 @@ Type: `number`

#### options.maxmemory
##### maxmemory

@@ -163,5 +152,11 @@ Type: `number`

#### 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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc