Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Add method to force the input format #589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "";
Expand Down
24 changes: 24 additions & 0 deletions test/setInputFormat.js
Original file line number Diff line number Diff line change
@@ -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);
});
}