Created
July 12, 2021 12:43
-
-
Save neodigm/655e29ca285cb0b6bbfd3fc1e05dba75 to your computer and use it in GitHub Desktop.
Automated image compression with Gulp and JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ltd_auto_image | |
// SCK 20160503 | Gulp script QA Product AND Static images (55k) | |
// Notes: NODE 5.10.0 | GULP 3.9.x | |
//. πππππππππ | |
var del = require('del'), | |
vinylPaths = require('vinyl-paths'), | |
gulp = require("gulp"), | |
debug = require("gulp-debug"), | |
imagemin = require("gulp-imagemin"), | |
jpegtran = require("imagemin-jpegtran"), | |
optipng = require("imagemin-optipng"), | |
pngquant = require("imagemin-pngquant"); | |
//mozjpeg = require("imagemin-mozjpeg"), | |
var ogConfig = require("./gconfig")(); | |
process.setMaxListeners(20); | |
gulp.task("images_watch", function() { | |
return gulp.src( ogConfig.sImages_in ) | |
.pipe(imagemin({ | |
progressive: true, | |
use: [pngquant(), jpegtran(), optipng()] | |
})).pipe( debug() ).pipe(vinylPaths(del)).pipe(gulp.dest( ogConfig.sImages_compressed )); | |
// LOSSY | |
//use: [pngquant(), mozjpeg({quality: oConfig.nJPGQuality}), optipng()] | |
}); | |
gulp.task("images_watch_s", function() { | |
return gulp.src( ogConfig.sImages_in_s ) | |
.pipe(imagemin({ | |
progressive: true, | |
use: [pngquant(), jpegtran(), optipng()] | |
})).pipe( debug() ).pipe(vinylPaths(del)).pipe(gulp.dest( ogConfig.sImages_compressed_s )); | |
// LOSSY | |
//use: [pngquant(), mozjpeg({quality: oConfig.nJPGQuality}), optipng()] | |
}); | |
gulp.task("default", ["images_watch","images_watch_s"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment