|
|
|
|
|
|
|
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Stream = require('stream').Stream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param {String|Number} path - path to img source or ReadableStream or width of img to create
|
|
|
|
* @param {Number} [height] - optional filename of ReadableStream or height of img to create
|
|
|
|
* @param {String} [color] - optional hex background color of created img
|
|
|
|
*/
|
|
|
|
|
|
|
|
function gm (source, height, color) {
|
|
|
|
var width;
|
|
|
|
|
|
|
|
if (!(this instanceof gm)) {
|
|
|
|
return new gm(source, height, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._options = {};
|
|
|
|
this.options(this.__proto__._options);
|
|
|
|
|
|
|
|
this.data = {};
|
|
|
|
this._in = [];
|
|
|
|
this._out = [];
|
|
|
|
|
|
|
|
if (source instanceof Stream) {
|
|
|
|
this.sourceStream = source;
|
|
|
|
source = height || 'unknown.jpg';
|
|
|
|
} else if (height) {
|
|
|
|
// new images
|
|
|
|
width = source;
|
|
|
|
source = "";
|
|
|
|
|
|
|
|
this.in("-size", width + "x" + height);
|
|
|
|
|
|
|
|
if (color) {
|
|
|
|
this.in("xc:"+ color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse out gif frame brackets from filename
|
|
|
|
// since stream doesn't use source path
|
|
|
|
// eg. "filename.gif[0]"
|
|
|
|
var frames;
|
|
|
|
if (frames = source.match(/(\[.+\])$/)) {
|
|
|
|
this.sourceFrames = source.substr(frames.index, frames[0].length);
|
|
|
|
source = source.substr(0, frames.index);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.source = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
var super = gm;
|
|
|
|
gm.subClass = function subClass (options) {
|
|
|
|
function gm (source, height, color) {
|
|
|
|
if (!(this instanceof super)) {
|
|
|
|
return new gm(source, height, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.call(this, source, height, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
gm.prototype.__proto__ = super.prototype;
|
|
|
|
gm.prototype._options = {};
|
|
|
|
gm.prototype.options(options);
|
|
|
|
|
|
|
|
return gm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Augment the prototype.
|
|
|
|
*/
|
|
|
|
|
|
|
|
require("./lib/options")(gm.prototype);
|
|
|
|
require("./lib/getters")(gm);
|
|
|
|
require("./lib/args")(gm.prototype);
|
|
|
|
require("./lib/drawing")(gm.prototype);
|
|
|
|
require("./lib/convenience")(gm.prototype);
|
|
|
|
require("./lib/command")(gm.prototype);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = exports = gm;
|
|
|
|
module.exports.version = "0.6.0";
|
|
|
|
|