1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var Stream = require('stream').Stream;
|
7 | var EventEmitter = require('events').EventEmitter;
|
8 | var util = require('util');
|
9 |
|
10 | util.inherits(gm, EventEmitter);
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function gm (source, height, color) {
|
21 | var width;
|
22 |
|
23 | if (!(this instanceof gm)) {
|
24 | return new gm(source, height, color);
|
25 | }
|
26 |
|
27 | EventEmitter.call(this);
|
28 |
|
29 | this._options = {};
|
30 | this.options(this.__proto__._options);
|
31 |
|
32 | this.data = {};
|
33 | this._in = [];
|
34 | this._out = [];
|
35 | this._outputFormat = null;
|
36 | this._subCommand = 'convert';
|
37 |
|
38 | if (source instanceof Stream) {
|
39 | this.sourceStream = source;
|
40 | source = height || 'unknown.jpg';
|
41 | } else if (Buffer.isBuffer(source)) {
|
42 | this.sourceBuffer = source;
|
43 | source = height || 'unknown.jpg';
|
44 | } else if (height) {
|
45 |
|
46 | width = source;
|
47 | source = "";
|
48 |
|
49 | this.in("-size", width + "x" + height);
|
50 |
|
51 | if (color) {
|
52 | this.in("xc:"+ color);
|
53 | }
|
54 | }
|
55 |
|
56 | if (typeof source === "string") {
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | var frames = source.match(/(\[.+\])$/);
|
63 | if (frames) {
|
64 | this.sourceFrames = source.substr(frames.index, frames[0].length);
|
65 | source = source.substr(0, frames.index);
|
66 | }
|
67 | }
|
68 |
|
69 | this.source = source;
|
70 |
|
71 | this.addSrcFormatter(function (src) {
|
72 |
|
73 |
|
74 | var inputFromStdin = this.sourceStream || this.sourceBuffer;
|
75 | var ret = inputFromStdin ? '-' : this.source;
|
76 |
|
77 | if (ret && this.sourceFrames) ret += this.sourceFrames;
|
78 |
|
79 | src.length = 0;
|
80 | src[0] = ret;
|
81 | });
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | var parent = gm;
|
92 | gm.subClass = function subClass (options) {
|
93 | function gm (source, height, color) {
|
94 | if (!(this instanceof parent)) {
|
95 | return new gm(source, height, color);
|
96 | }
|
97 |
|
98 | parent.call(this, source, height, color);
|
99 | }
|
100 |
|
101 | gm.prototype.__proto__ = parent.prototype;
|
102 | gm.prototype._options = {};
|
103 | gm.prototype.options(options);
|
104 |
|
105 | return gm;
|
106 | }
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | require("./lib/options")(gm.prototype);
|
113 | require("./lib/getters")(gm);
|
114 | require("./lib/args")(gm.prototype);
|
115 | require("./lib/drawing")(gm.prototype);
|
116 | require("./lib/convenience")(gm.prototype);
|
117 | require("./lib/command")(gm.prototype);
|
118 | require("./lib/compare")(gm.prototype);
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | module.exports = exports = gm;
|
125 | module.exports.utils = require('./lib/utils');
|
126 | module.exports.compare = require('./lib/compare')();
|
127 | module.exports.version = JSON.parse(
|
128 | require('fs').readFileSync(__dirname + '/package.json', 'utf8')
|
129 | ).version;
|
130 |
|