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

Proper configuration of imagemin plugins #190

Closed
nlenkowski opened this issue Jun 30, 2016 · 6 comments
Closed

Proper configuration of imagemin plugins #190

nlenkowski opened this issue Jun 30, 2016 · 6 comments

Comments

@nlenkowski
Copy link

I've been trying unsuccessfully to to get the imagemin-pngquant plugin working with gulp-imagemin. No matter what I try my pngs are not compressed with pngquant. Here's my config:

package.json

"gulp": "^3.9.1",
"gulp-imagemin": "^3.0.1",
"imagemin-pngquant": "^5.0.0",

gulpfile.js

var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');

gulp.task('images', function() {
    return gulp.src(paths.assets + 'images/**/*.+(png|jpg|gif|jpeg)')
        .pipe(imagemin({
            verbose: true,
            progressive: true,
            plugins: [pngquant()]
        }))
        .pipe(gulp.dest(paths.dist + 'images'));
});

I've tried switching plugins: [pngquant()] to the old value use: [pngquant()], to no affect.

When running the images task with the above configuration I'm getting the following results:
alex.png (saved 63.87 kB - 19.6%).

When I remove the plugins: [pngquant()] option I get the same:
alex.png (saved 63.87 kB - 19.6%)

For comparison, when using gulp-image (which uses pngquant out of the box) I'm getting the following results for the same file:
alex.png -> before=318.79 KB after=150.62 KB reduced=168.17 KB(52.8%)

I'm on OS X 10.11.5 running node v6.2.2. I'm not sure if this is a problem with gulp-imagemin, imagemin-pngquant or my configuration.

@shinnn
Copy link
Contributor

shinnn commented Jun 30, 2016

https://github.com/sindresorhus/gulp-imagemin#imageminplugins-options

imagemin([plugins], [options])

imagemin({plugins: [...]}) is wrong usage.

@shinnn shinnn closed this as completed Jun 30, 2016
@joeskeen
Copy link

@shinnn I understand that imagemin({...}) is wrong usage, but is there a way to specify options without having to change the plugins? I would like to keep the default plugins but specify custom options. If I do something like imagemin(null, {...}) will it keep the defaults?

@shinnn
Copy link
Contributor

shinnn commented Jun 30, 2016

@joeskeen imagemin({verbose: true}) works.

gulp-imagemin/index.js

Lines 15 to 18 in bf8d842

if (typeof plugins === 'object' && !Array.isArray(plugins)) {
opts = plugins;
plugins = null;
}

@nlenkowski
Copy link
Author

nlenkowski commented Jun 30, 2016

@shinnn Thanks for putting me on the right track. It appears I was providing options for imagemin, which are a bit different from gulp-imagemin. Several boilperplates I referenced had gulp-imagemin configured incorrectly, I should have just gone right to the source.

The following configuration works great:

var imagemin = require('gulp-imagemin');
var imageminJpg = require('imagemin-jpeg-recompress');
var imageminPng = require('imagemin-pngquant');

.pipe(imagemin(
    [imageminPng(), imageminJpg()],
    {verbose: true}
))

With default configuration:

[20:40:45] gulp-imagemin: ✔ mountain.jpeg (saved 984 B - 0.1%)
[20:40:55] gulp-imagemin: ✔ alex.png (saved 63.87 kB - 19.6%)
[20:40:55] gulp-imagemin: Minified 2 images (saved 64.86 kB - 3.4%)
[20:40:55] Finished 'images' after 9.93 s

With pngquant and jpeg-recompress plugins enabled:

[20:43:30] gulp-imagemin: ✔ alex.png (saved 172.43 kB - 52.8%)
[20:43:31] gulp-imagemin: ✔ mountain.jpeg (saved 1.02 MB - 65.3%)
[20:43:31] gulp-imagemin: Minified 2 images (saved 1.19 MB - 63.1%)
[20:43:31] Finished 'images' after 1.12 s

Thanks again!

@nlenkowski nlenkowski changed the title Pngquant plugin not working Proper configuration of imagemin plugins Jun 30, 2016
@shinnn
Copy link
Contributor

shinnn commented Jun 30, 2016

You're welcome, @nlenkowski.

Several boilperplates I referenced had gulp-imagemin configured incorrectly,

I'd be glad if you could report this breaking change to the authors of those boilerplates when you have a time.

@nlenkowski
Copy link
Author

Will do 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants