-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelper.js
36 lines (32 loc) · 1008 Bytes
/
helper.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
var exec = require('child_process').exec
module.exports = (function (exec) {
function generateCmd (options) {
var filters = {
blur : ' -channel RGBA -blur 0x',
gaussian : ' -filter Gaussian -define filter:sigma=',
sharpen : ' -sharpen 0x',
unsharp : ' -unsharp 0x',
threshold : ' -threshold ',
oilpaint : ' -paint ',
sketch : ' -sketch ',
metal : ' -colorspace Gray -emboss 0x',
edge : ' -negate -colorspace Gray -edge '
}
return "convert " + options.image
+ " " + filters[options.filter] + (options.level || 5)
+ " -resize " + (options.size || 100) + "%"
+ " " + ( options.to || options.image );
}
function executeCommand (cmd, callback) {
exec(cmd, function (error) {
callback(error);
});
}
return {
applyEffect : function (effect, options, callback) {
options.filter = effect;
var cmd = generateCmd(options);
executeCommand(cmd, callback);
}
}
}) (exec);