1
+
2
+
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
3
+
4
+
5
+
var exec = require('child_process').exec
6
+
, gm = {}
7
+
8
+
9
+
gm.Image = function(utility, input) {
10
+
this.input = input
11
+
this.inArgs = [utility]
12
+
this.outArgs = []
13
+
}
14
+
15
+
gm.Image.prototype =
16
+
{ size: function(width, height){
17
+
return this.makeArgs(["-size", width + "x" + height])
18
+
}
19
+
, _noProfileArg: function(){
20
+
return ['+profile "*"']
21
+
}
22
+
, _resizeArg: function(width, height) {
23
+
return ["-resize", width + "x" + height]
24
+
}
25
+
, makeArgs: function(inargs, outargs) {
26
+
if (inargs)
27
+
this.inArgs = this.inArgs.concat(inargs)
28
+
if (outargs)
29
+
this.outArgs = this.outArgs.concat(outargs)
30
+
return this
31
+
}
32
+
, cmd: function() {
33
+
return "gm "
34
+
+ this.inArgs.join(" ") + " "
35
+
+ this.input + " "
36
+
+ this.outArgs.join(" ")
37
+
}
38
+
, write: function(callback){
39
+
var cmd = this.cmd()
40
+
exec(cmd, function(err, stdout, stderr){
41
+
callback(err, stdout, stderr, cmd);
42
+
})
43
+
}
44
+
}
45
+
46
+
47
+
gm.Mogrify = function(image) {
48
+
gm.Image.call(this, 'mogrify', image)
49
+
}
50
+
function mog() {}
51
+
mog.prototype = gm.Image.prototype
52
+
;(gm.Mogrify.prototype = new mog).constructor = gm.Mogrify
53
+
54
+
gm.Mogrify.prototype.format = function(format){
55
+
return this.makeArgs(["-format", format])
56
+
}
57
+
gm.Mogrify.prototype.dir = function(dir) {
58
+
return this.makeArgs(["-output-directory", dir])
59
+
}
60
+
gm.Mogrify.prototype.createDir = function(dir) {
61
+
return this.makeArgs(["-create-directories"])
62
+
}
63
+
gm.Mogrify.prototype.resize = function(width, height){
64
+
return this.makeArgs(this._resizeArg(width, height))
65
+
}
66
+
gm.Mogrify.prototype.noProfile = function() {
67
+
return this.makeArgs(this._noProfileArg())
68
+
}
69
+
70
+
71
+
gm.Convert = function(image) {
72
+
gm.Image.call(this, 'convert', image)
73
+
}
74
+
function con(){}
75
+
con.prototype = gm.Image.prototype
76
+
;(gm.Convert.prototype = new con).constructor = gm.Convert
77
+
78
+
gm.Convert.prototype.resize = function(width, height){
79
+
return this.makeArgs(null, this._resizeArg(width, height))
80
+
}
81
+
gm.Convert.prototype.noProfile = function() {
82
+
return this.makeArgs(null, this._noProfileArg())
83
+
}
84
+
gm.Convert.prototype.name = function(filename) {
85
+
return this.makeArgs(null, [filename])
86
+
}
87
+
88
+
89
+
exports.Image = gm.Image
90
+
91
+
exports.mogrify = function(image) {
92
+
return new gm.Mogrify(image)
93
+
}
94
+
exports.convert = function(image) {
95
+
return new gm.Convert(image)
96
+
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4