forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresizeRetinaImages.js
More file actions
executable file
·40 lines (30 loc) · 977 Bytes
/
resizeRetinaImages.js
File metadata and controls
executable file
·40 lines (30 loc) · 977 Bytes
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
const es = require('event-stream');
const path = require('path');
const gulp = require('gulp');
const gp = require('gulp-load-plugins')();
const gutil = require('gulp-util');
const fs = require('fs');
const gm = require('gm');
/**
* Resize all @2x. images to normal resolution
* @param options
* options.root => the root to resize from
* @returns {Function}
*/
module.exports = function(options) {
options = options || {};
const root = options.root || require('yargs').argv.root;
if (!root) {
throw new Error("Root not set");
}
return function(callback) {
gutil.log("resize retina images " + root);
return gulp.src(root + '/**/*@2x.{png,jpg,gif}')
.pipe(gp.debug())
.pipe(es.map(function(file, cb) {
var normalResolutionPath = file.path.replace(/@2x(?=\.[^.]+$)/, '');
gutil.log(file.path + ' -> ' + normalResolutionPath);
gm(file.path).resize("50%").write(normalResolutionPath, cb);
}));
};
};