Smoother gulp advpng

less than 1 minute read

Streamline advpng usage in your gulp build

This is a spiritual successor to my previous post, Smoother gulp advzip.

A quick tip: if you use advpng in your build pipeline, note that you can now pass the iterations (--iter) option through the imagemin-advpng plugin. If you haven’t used it before, it looks something like this:

    // gulpfile.js

    const imagemin = require('imagemin');
    const advpng = require('imagemin-advpng');

    gulp.task('mytask', () => {
        return gulp.src(['assets/*.png'])
            .pipe(imagemin({ use: advpng({ optimizationLevel: 4 }) }))
            .pipe(gulp.dest('out'));
    });

Using the latest version of imagemin-advpng, you can now specify iterations as well; ideal for that last-pass squeeze-everything-we-possibly-can build of your js13k project:

        return gulp.src(['assets/*.png'])
            .pipe(imagemin({ use: advpng({ optimizationLevel: 4, iterations: 5000 }) }))
            .pipe(gulp.dest('out'));

Leave a comment