gm().toBuffer()

master
Jonathan Ong 11 years ago
parent 262378d182
commit 8f0d27f49e
  1. 23
      lib/command.js
  2. 18
      test/toBuffer.js
  3. 18
      test/toBufferFormat.js

@ -127,6 +127,29 @@ module.exports = function (proto) {
return throughStream
}
/**
* Convenience function for `proto.stream`.
* Simply returns the buffer instead of the stream.
*
* @param {String} format (optional)
* @param {Function} callback
* @return {null}
*/
proto.toBuffer = function toBuffer (format, callback) {
if (!callback) callback = format, format = null;
if ("function" !== typeof callback) {
throw new Error('gm().toBuffer() expects a callback.');
}
return this.stream(format, function (err, stdout) {
if (err) return callback(err);
utils.streamToBuffer(stdout, callback);
})
}
/**
* Run any preProcessor functions in series. Used by autoOrient.
*

@ -0,0 +1,18 @@
var assert = require('assert');
var fs = require('fs');
module.exports = function (gm, dir, finish, GM) {
if (!GM.integration)
return finish();
gm
.toBuffer(function (err, buffer) {
if (err) return finish(err);
assert.ok(buffer instanceof Buffer);
assert.ok(buffer.length);
finish();
})
}

@ -0,0 +1,18 @@
var assert = require('assert');
var fs = require('fs');
module.exports = function (gm, dir, finish, GM) {
if (!GM.integration)
return finish();
gm
.toBuffer('PNG', function (err, buffer) {
if (err) return finish(err);
assert.ok(buffer instanceof Buffer);
assert.ok(buffer.length);
finish();
})
}
Loading…
Cancel
Save