Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace jpegtran with mozjpeg #336

Merged
Binary file added fixture.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const imagemin = require('imagemin');
const plur = require('plur');

const PLUGIN_NAME = 'gulp-imagemin';
const defaultPlugins = ['gifsicle', 'jpegtran', 'optipng', 'svgo'];
const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];

const loadPlugin = (plugin, ...args) => {
try {
Expand Down Expand Up @@ -119,6 +119,6 @@ module.exports = (plugins, options) => {
};

module.exports.gifsicle = exposePlugin('gifsicle');
module.exports.jpegtran = exposePlugin('jpegtran');
module.exports.mozjpeg = exposePlugin('mozjpeg');
module.exports.optipng = exposePlugin('optipng');
module.exports.svgo = exposePlugin('svgo');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"optionalDependencies": {
"imagemin-gifsicle": "^6.0.1",
"imagemin-jpegtran": "^6.0.0",
"imagemin-mozjpeg": "^8.0.0",
"imagemin-optipng": "^7.0.0",
"imagemin-svgo": "^7.0.0"
},
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.default = () => (
// …
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.mozjpeg({quality: 75, progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
Expand Down Expand Up @@ -86,7 +86,7 @@ Note that you may come across an older, implicit syntax. In versions < 3, the sa
Comes bundled with the following **lossless** optimizers:

- [gifsicle](https://github.com/imagemin/imagemin-gifsicle) — *Compress GIF images*
- [jpegtran](https://github.com/imagemin/imagemin-jpegtran) — *Compress JPEG images*
- [mozjpeg](https://github.com/imagemin/imagemin-mozjpeg) — *Compress JPEG images*
- [optipng](https://github.com/imagemin/imagemin-optipng) — *Compress PNG images*
- [svgo](https://github.com/imagemin/imagemin-svgo) — *Compress SVG images*

Expand All @@ -99,9 +99,9 @@ Unsupported files are ignored.
#### plugins

Type: `Array`<br>
Default: `[imagemin.gifsicle(), imagemin.jpegtran(), imagemin.optipng(), imagemin.svgo()]`
Default: `[imagemin.gifsicle(), imagemin.mozjpeg(), imagemin.optipng(), imagemin.svgo()]`

[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use. This will overwrite the default plugins. Note that the default plugins comes with good defaults and should be sufficient in most cases. See the individual plugins for supported options.
[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use. This will completely overwrite all the default plugins. So, if you want to use custom plugins and you need some of defaults too, then you should pass default plugins as well. Note that the default plugins come with good defaults and should be sufficient in most cases. See the individual plugins for supported options.

#### options

Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ test('minify images', async t => {
t.true(file[0].contents.length < buffer.length);
});

test('minify JPEG with custom settings', async t => {
const mozjpegOptions = {
quality: 30,
progressive: false,
smooth: 45
};
const {buffer, stream} = await createFixture([gulpImagemin.mozjpeg(mozjpegOptions)], 'fixture.jpg');
const file = await getStream.array(stream);

t.true(file[0].contents.length < buffer.length);
});

test('use custom plugins', async t => {
const {stream} = await createFixture([imageminPngquant()]);
const compareStream = (await createFixture()).stream;
Expand Down