Aaron Heckmann 13 years ago
parent aab1667ff5
commit 774fb509c7
  1. 4
      index.js
  2. 4
      lib/args.js
  3. 24
      lib/command.js
  4. 8
      lib/getters.js
  5. 4
      test/streamIn.js
  6. 4
      test/streamInGetter.js

@ -26,7 +26,7 @@ function gm (source, height, color) {
this._in = [];
this._out = [];
if(source instanceof Stream) {
if (source instanceof Stream) {
this.sourceStream = source;
source = height || 'unknown.jpg';
} else if (height) {
@ -46,7 +46,7 @@ function gm (source, height, color) {
// since stream doesn't use source path
// eg. "filename.gif[0]"
var frames;
if(frames = source.match(/(\[.+\])$/)) {
if (frames = source.match(/(\[.+\])$/)) {
this.sourceFrames = source.substr(frames.index, frames[0].length);
source = source.substr(0, frames.index);
}

@ -305,10 +305,10 @@ module.exports = function (proto) {
proto.type = function type (type) {
return this.in("-type", type);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-trim
proto.trim = function trim () {
return this.out("-trim");
return this.out("-trim");
}
};

@ -40,11 +40,11 @@ module.exports = function (proto) {
* @param {Function} callback
* @return {Object} gm
*/
proto.write = function write (name, callback) {
if (!callback) callback = name, name = null;
if (typeof callback !== "function") {
if ("function" !== typeof callback) {
throw new TypeError("gm().write() expects a callback function")
}
@ -65,13 +65,13 @@ module.exports = function (proto) {
*/
proto.stream = function stream (format, callback) {
if(!callback) callback = format, format = null;
if (!callback) callback = format, format = null;
if (typeof callback !== "function") {
if ("function" !== typeof callback) {
throw new TypeError("gm().stream() expects a callback function")
}
if(format) {
if (format) {
format = format.split('.').slice(-1)[0].toUpperCase();
this.outname = format + ":-";
}
@ -110,9 +110,9 @@ module.exports = function (proto) {
, err;
// pipe in the sourceStream if present
if(self.sourceStream) {
if (self.sourceStream) {
if(!self.sourceStream.readable && !self.bufferStream) {
if (!self.sourceStream.readable && !self.bufferStream) {
err = new Error("gm().stream() or gm().write() with a non-readable " +
"stream. Pass \"{bufferStream: true}\" to identify() " +
"or getter (size, format, etc...)");
@ -122,19 +122,19 @@ module.exports = function (proto) {
self.sourceStream.pipe(proc.stdin);
// resume any buffered events from a previous identify operation
if(self.buffer) {
if (self.buffer) {
self.buffer.resume();
// if {bufferStream: true} was passed to an identify operation,
// we buffer the input stream events so we can use them again
} else if(self.bufferStream) {
} else if (self.bufferStream) {
self.buffer = utils.buffer(self.sourceStream);
}
}
// for _exec operations (identify() mostly), we also
// need to buffer the output stream before returning
if(bufferOutput) {
if (bufferOutput) {
var stdout = ''
, stderr = '';
@ -164,14 +164,14 @@ module.exports = function (proto) {
proto.args = function args () {
var source = (this.sourceStream ? "-" : this.source);
if(source && this.sourceFrames) source += this.sourceFrames;
if (source && this.sourceFrames) source += this.sourceFrames;
return [].concat(
'convert'
, this._in
, source
, this._out
, this.outname || "-"
).filter(function(arg) { return !!arg });
).filter(Boolean); // remove falsey
}
/**

@ -8,9 +8,9 @@
module.exports = function (proto) {
;['size', 'format', 'depth', 'color', 'res', 'filesize'].forEach(function (getter) {
proto[getter] = function (opts, callback) {
if(!callback) callback = opts, opts = {};
if (!callback) callback = opts, opts = {};
var self = this;
if (self.data[getter]) {
@ -31,13 +31,13 @@ module.exports = function (proto) {
});
proto.identify = function identify (opts, callback) {
if(!callback) callback = opts, opts = {};
if (!callback) callback = opts, opts = {};
var self = this;
if (!callback) return self;
self.bufferStream = opts.bufferStream == true;
self.bufferStream = !! opts.bufferStream;
if (self._identifying) {
self._iq.push(callback);

@ -4,9 +4,9 @@
var fs = require('fs');
module.exports = function (_, dir, finish, gm) {
gm(fs.createReadStream(dir + '/original.jpg'), "original.jpg")
.write(dir + '/streamIn.png', function streamIn (err){
.write(dir + '/streamIn.png', function streamIn (err) {
finish(err);
});
}

@ -4,9 +4,9 @@
var fs = require('fs');
module.exports = function (_, dir, finish, gm) {
gm(fs.createReadStream(dir + '/original.jpg'), "original.jpg")
.size({bufferStream: true}, function(err, size) {
.size({bufferStream: true}, function (err, size) {
this.write(dir + '/streamInGetter.png', function streamInGetter (err){
finish(err);
});

Loading…
Cancel
Save