Skip to content

Instantly share code, notes, and snippets.

@LoyEgor
Last active March 2, 2018 22:43
Show Gist options
  • Save LoyEgor/cd548f5795b36ced711f2c3142f1452f to your computer and use it in GitHub Desktop.
Save LoyEgor/cd548f5795b36ced711f2c3142f1452f to your computer and use it in GitHub Desktop.
resize images for responsive use
// install
// cd node_modules \
// chmod -R a+rwX .
// run without sudo
// npm i del gulp-responsive --unsafe-perm
var del = require('del');
var responsive = require('gulp-responsive');
// Global configuration for all images
var resimgconfig = {
// Use progressive (interlace) scan for JPEG and PNG output
progressive: true,
// Strip all metadata
withMetadata: false,
errorOnEnlargement: false,
withoutEnlargement: true, // copy original file with/without renaming
skipOnEnlargement: false,
};
// create thumbnails for portfolio
gulp.task('resimg:portfolio', function() {
// size of portfolio tumb
var tumbport = 240;
var sharpfix = 1.3;
// processing directories
var dirorig = './app/img/portfolio/'
var dirtumb = './app/img/tumb/portfolio/'
// remove tumb sub folders
del.sync(dirtumb);
// create tumbs
return gulp.src(dirorig + '**/*.*')
.pipe(responsive({
'**': [{
// convert png to jpg
flatten: true, // add backgoround #fff need instal npm i color
rename: {
extname: '.jpg' // rename ext and converting (converting format get from extname)
},
// end converting
width: tumbport,
height: tumbport,
quality: 90,
//min: true, // min size will be tumbport ()
max: true // max size will be tumbport
}, {
width: tumbport / 2,
quality: 60,
blur: true,
rename: {
suffix: '-placeholder'
},
}],
}, resimgconfig))
.pipe(gulp.dest(dirtumb));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment