-
Notifications
You must be signed in to change notification settings - Fork 0
/
svg2png.js
41 lines (29 loc) · 969 Bytes
/
svg2png.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
'use strict';
var through = require('through2');
var gutil = require('gulp-util');
var sharp = require('sharp');
var PLUGIN_NAME = 'svg2png';
function svg2png(options) {
return through.obj(function (file, encoding, callback) {
if (file.isNull()) {
this.push(file)
return callback();
}
if (file.isStream()) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, "Received a stream... Streams are not supported. Sorry."));
return callback();
}
if (file.isBuffer()) {
var image = sharp(file.contents).resize(options.width, options.height).png();
var newFile = new gutil.File({
cwd: file.cwd,
base: file.base,
path: file.path,
contents: image
});
newFile.extname = '.png';
callback(null, newFile);
}
});
}
module.exports = svg2png;