-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
59 lines (49 loc) · 1.61 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var gulp = require('gulp'),
minimist = require('minimist'),
imageOp = require('gulp-image-optimization'),
imageResize = require('gulp-image-resize'),
rename = require('gulp-rename');
var knownOptions = {
string: ['width', 'output', 'height', 'optimizationLevel'],
boolean: ['crop', 'upscale', 'progressive', 'interlaced'],
default: {
width: '1200',
output: './resized',
crop: false,
upscale: false,
height: null,
optimizationLevel: '5',
progessive: true,
interlaced: true
}
};
var options = minimist(process.argv.slice(2), knownOptions);
gulp.task('resize', function() {
var resizeOpts = {
width: parseInt(options.width),
height: parseInt(options.height) || null,
crop: options.crop,
upscale: options.upscale
};
var optimizationOpts ={
optimizationLevel: parseInt(options.optimizationLevel),
progressive: options.progressive,
interlaced: options.interlaced
};
var extensions = ['jpg', 'jpeg', 'png', 'gif'];
var src = [];
for (var i = 0; i < extensions.length; i++) {
src.push('original/**/*.' + extensions[i]);
src.push('original/**/*.' + extensions[i].toUpperCase());
}
return gulp
.src(src)
.pipe(imageResize(resizeOpts))
// imageop doesn't recognize files with uppercase exentions
.pipe(rename(function(path) {
path.extname = path.extname.toLowerCase();
}))
.pipe(imageOp(optimizationOpts))
.pipe(gulp.dest(options.output));
});
gulp.task('default', ['resize']);