diff --git a/index.js b/index.js index 8f5f8d54..eab6a488 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,7 @@ function gm (source, height, color) { this._in = []; this._out = []; this._outputFormat = null; + this._inputFormat = null; this._subCommand = 'convert'; if (source instanceof Stream) { @@ -74,6 +75,10 @@ function gm (source, height, color) { var inputFromStdin = this.sourceStream || this.sourceBuffer; var ret = inputFromStdin ? '-' : this.source; + if (this._inputFormat) { + ret = this._inputFormat + ':' + ret; + } + if (ret && this.sourceFrames) ret += this.sourceFrames; src.length = 0; diff --git a/lib/args.js b/lib/args.js index 35089f77..bc5777db 100644 --- a/lib/args.js +++ b/lib/args.js @@ -721,6 +721,12 @@ module.exports = function (proto) { return this; } + // force input format + proto.setInputFormat = function setInputFormat (format) { + if (format) this._inputFormat = format; + return this; + } + // http://www.graphicsmagick.org/GraphicsMagick.html#details-resize proto.resize = function resize (w, h, options) { options = options || ""; diff --git a/test/setInputFormat.js b/test/setInputFormat.js new file mode 100644 index 00000000..fa0fdd00 --- /dev/null +++ b/test/setInputFormat.js @@ -0,0 +1,24 @@ + +var assert = require('assert') + +module.exports = function (gm, dir, finish, GM) { + + var m = gm + .setInputFormat('jpeg'); + + assert.equal('jpeg', m._inputFormat); + + assert.deepEqual(m.args(), [ + 'convert', + 'jpeg:' + dir + '/original.jpg', + '-' + ]); + + if (!GM.integration) + return finish(); + + m + .write(dir + '/setInputformat', function setInputformat (err) { + finish(err); + }); +}