Skip to content

Commit 279a91b

Browse files
tjbulicksindresorhus
authored andcommittedJan 16, 2020
Replace jpegtran with mozjpeg (#336)
1 parent f4a2255 commit 279a91b

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed
 

‎fixture.jpg

49.8 KB
Loading

‎index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const imagemin = require('imagemin');
88
const plur = require('plur');
99

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

1313
const loadPlugin = (plugin, ...args) => {
1414
try {
@@ -119,6 +119,6 @@ module.exports = (plugins, options) => {
119119
};
120120

121121
module.exports.gifsicle = exposePlugin('gifsicle');
122-
module.exports.jpegtran = exposePlugin('jpegtran');
122+
module.exports.mozjpeg = exposePlugin('mozjpeg');
123123
module.exports.optipng = exposePlugin('optipng');
124124
module.exports.svgo = exposePlugin('svgo');

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
},
5353
"optionalDependencies": {
5454
"imagemin-gifsicle": "^6.0.1",
55-
"imagemin-jpegtran": "^6.0.0",
55+
"imagemin-mozjpeg": "^8.0.0",
5656
"imagemin-optipng": "^7.0.0",
5757
"imagemin-svgo": "^7.0.0"
5858
},

‎readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ exports.default = () => (
3333
//
3434
.pipe(imagemin([
3535
imagemin.gifsicle({interlaced: true}),
36-
imagemin.jpegtran({progressive: true}),
36+
imagemin.mozjpeg({quality: 75, progressive: true}),
3737
imagemin.optipng({optimizationLevel: 5}),
3838
imagemin.svgo({
3939
plugins: [
@@ -86,7 +86,7 @@ Note that you may come across an older, implicit syntax. In versions < 3, the sa
8686
Comes bundled with the following **lossless** optimizers:
8787

8888
- [gifsicle](https://github.com/imagemin/imagemin-gifsicle)*Compress GIF images*
89-
- [jpegtran](https://github.com/imagemin/imagemin-jpegtran)*Compress JPEG images*
89+
- [mozjpeg](https://github.com/imagemin/imagemin-mozjpeg)*Compress JPEG images*
9090
- [optipng](https://github.com/imagemin/imagemin-optipng)*Compress PNG images*
9191
- [svgo](https://github.com/imagemin/imagemin-svgo)*Compress SVG images*
9292

@@ -99,9 +99,9 @@ Unsupported files are ignored.
9999
#### plugins
100100

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

104-
[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.
104+
[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.
105105

106106
#### options
107107

‎test.js

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ test('minify images', async t => {
2828
t.true(file[0].contents.length < buffer.length);
2929
});
3030

31+
test('minify JPEG with custom settings', async t => {
32+
const mozjpegOptions = {
33+
quality: 30,
34+
progressive: false,
35+
smooth: 45
36+
};
37+
const {buffer, stream} = await createFixture([gulpImagemin.mozjpeg(mozjpegOptions)], 'fixture.jpg');
38+
const file = await getStream.array(stream);
39+
40+
t.true(file[0].contents.length < buffer.length);
41+
});
42+
3143
test('use custom plugins', async t => {
3244
const {stream} = await createFixture([imageminPngquant()]);
3345
const compareStream = (await createFixture()).stream;

0 commit comments

Comments
 (0)
Please sign in to comment.