Created
June 1, 2017 13:27
-
-
Save fraterblack/a62252fec5e4aada93f9a75c169f89a2 to your computer and use it in GitHub Desktop.
Task para redimensionar, compactar e zipar as imagens JPG de um diretório
This file contains 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
/* | |
//Dependências | |
"devDependencies": { | |
"gulp": "^3.9.1", | |
"gulp-image": "^2.9.0", | |
"gulp-image-resize": "^0.12.0", | |
"gulp-zip": "^4.0.0" | |
} | |
*/ | |
const gulp = require('gulp'); | |
const imageresize = require('gulp-image-resize'); | |
const image = require('gulp-image'); | |
const zip = require('gulp-zip'); | |
const fs = require('fs'); | |
const albums = [ | |
{ | |
src: 'C:/fotos/meudiretorio1/' | |
}, | |
{ | |
src: 'C:/fotos/meudiretorio2/' | |
} | |
]; | |
function slugify(text) | |
{ | |
return text.toString().toLowerCase() | |
.replace(/\s+/g, '-') // Replace spaces with - | |
.replace(/[^\w\-]+/g, '') // Remove all non-word chars | |
.replace(/\-\-+/g, '-') // Replace multiple - with single - | |
.replace(/^-+/, '') // Trim - from start of text | |
.replace(/-+$/, ''); // Trim - from end of text | |
} | |
gulp.task('images', function () { | |
// loop through image groups | |
albums.forEach(function(album){ | |
var fileName = album.src.match(/([^\/]*)\/*$/)[1]; | |
var resize_settings = { | |
width: 900, | |
height: 900, | |
crop: false, | |
upscale : false | |
} | |
gulp | |
.src([album.src + '*.jpg', album.src + '*.JPG']) | |
.pipe(imageresize(resize_settings)) | |
.pipe(image({ | |
//pngquant: true, | |
//optipng: false, | |
//zopflipng: true, | |
jpegRecompress: false, | |
jpegoptim: true, | |
mozjpeg: true, | |
guetzli: false, | |
//gifsicle: true, | |
//svgo: true, | |
concurrent: 10 | |
})) | |
.pipe(zip(slugify(fileName) + '.zip')) | |
.pipe(gulp.dest('./')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment