identify custom format added

master
tornillo 11 years ago
parent bb9f87688e
commit a1aaf0222c
  1. 32
      lib/getters.js
  2. 2
      test/autoOrientAndThumb.js
  3. 19
      test/getterIdentify.js
  4. 2
      test/resizeAndAutoOrientFromBuffer.js
  5. 2
      test/resizeBuffer.js

@ -95,6 +95,10 @@ module.exports = function (gm) {
*/
proto.identify = function identify (opts, callback) {
// identify with pattern
if (typeof(opts) === 'string') {
return identifyPattern.apply(this, arguments);
}
if (!callback) callback = opts, opts = {};
if (!callback) return this;
@ -139,6 +143,34 @@ module.exports = function (gm) {
return self;
}
/**
* identify with pattern
*
* Execute `identify -format` with custom pattern
*/
function identifyPattern (pattern, opts, callback) {
if (!callback) callback = opts, opts = {};
if (!callback) return this;
var self = this;
self.bufferStream = !!opts.bufferStream;
var args = makeArgs(self, { format: pattern });
self._exec(args, function (err, stdout, stderr, cmd) {
if (err) {
return callback.call(self, err, undefined, stdout, stderr, cmd);
}
callback.call(self, err, (stdout||'').trim());
});
return self;
}
/**
* Parses `identify` responses.
*

@ -31,7 +31,7 @@ module.exports = function (_, dir, finish, gm) {
function size (file, cb) {
gm(file).identify(result, function (err, data) {
gm(file).identify(function (err, data) {
if (err) return cb(err);
cb(err, data.size);
});

@ -59,10 +59,12 @@ module.exports = function (_, dir, finish, gm) {
assert.equal(d['Geometry'], '430x488');
}
gif();
gif(function () {
pattern();
});
});
function gif () {
function gif (callback) {
var test = gm(dir + '/blue.gif');
if (im) test.options({ imageMagick: true });
test.identify(function (err) {
@ -95,6 +97,19 @@ module.exports = function (_, dir, finish, gm) {
assert.ok(blackWorks);
}
callback();
});
}
function pattern () {
var test = gm(dir + '/blue.gif');
if (im) test.options({ imageMagick: true });
test.identify('%f: %m, %wx%h', function (err, result) {
if (err) return finish(err);
assert.equal(result, 'blue.gif: GIF, 100x200');
finish();
});
}

@ -43,7 +43,7 @@ module.exports = function (_, dir, finish, gm) {
function size (file, cb) {
gm(file).identify(result, function (err, data) {
gm(file).identify(function (err, data) {
if (err) return cb(err);
cb(err, data.size);
});

@ -42,7 +42,7 @@ module.exports = function (_, dir, finish, gm) {
function size (file, cb) {
gm(file).identify(result, function (err, data) {
gm(file).identify(function (err, data) {
if (err) return cb(err);
cb(err, data.size);
});

Loading…
Cancel
Save