Skip to content

Commit

Permalink
Add back format inference from filename
Browse files Browse the repository at this point in the history
  • Loading branch information
adurrive committed Jan 27, 2016
1 parent d8e8d84 commit 4301111
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ examples/imgs/*
!examples/imgs/photo.JPG
!examples/imgs/orientation/*\d.jpg
!examples/imgs/orientation/*.correct.jpg
!examples/imgs/icon.ico
*.sw*
.idea
Binary file added examples/imgs/icon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function gm (source, height, color) {
var inputFromStdin = this.sourceStream || this.sourceBuffer;
var ret = inputFromStdin ? '-' : this.source;

if (inputFromStdin && this.source && this.source !== 'unknown.jpg') ret = this.source.split('.').pop() + ':-';
if (ret && this.sourceFrames) ret += this.sourceFrames;

src.length = 0;
Expand Down
6 changes: 5 additions & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ module.exports = function (proto) {
} catch (e) {
return cb(e);
}
proc.stdin.once('error', cb);
proc.stdin.on('error', function (err) {
if (err.code !== 'ECONNRESET') {
cb(err);
}
});

if (timeout) {
timeoutId = setTimeout(function(){
Expand Down
21 changes: 21 additions & 0 deletions test/formatInference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var assert = require('assert')
var fs = require('fs');

module.exports = function (_, dir, finish, gm) {
var m = gm(fs.createReadStream(dir + '/icon.ico'), 'icon.ico')

var args = m.args();
assert.equal('convert', args[0]);
assert.equal('ico:-', args[1]);

if (!gm.integration)
return finish();

m
.size({bufferStream: true}, function (err, size) {
if (err) return finish(err);
assert.equal(128, size.width);
assert.equal(128, size.height);
finish();
});
}
2 changes: 1 addition & 1 deletion test/gifFrameStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function (_, dir, finish, gm) {

var args = m.args();
assert.equal('convert', args[0]);
assert.equal('-[0]', args[1]);
assert.equal('gif:-[0]', args[1]);

if (!gm.integration)
return finish();
Expand Down
2 changes: 1 addition & 1 deletion test/resizeAndAutoOrientFromBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (_, dir, finish, gm) {

var args = m.args();
assert.equal('convert', args[0]);
assert.equal('-', args[1]);
assert.equal('jpg:-', args[1]);
assert.equal('-resize', args[2]);
if (m._options.imageMagick) {
assert.equal('20%', args[3]);
Expand Down
2 changes: 1 addition & 1 deletion test/resizeBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function (_, dir, finish, gm) {

var args = m.args();
assert.equal('convert', args[0]);
assert.equal('-', args[1]);
assert.equal('jpg:-', args[1]);
assert.equal('-resize', args[2]);
if (m._options.imageMagick) {
assert.equal('48%', args[3]);
Expand Down
3 changes: 1 addition & 2 deletions test/streamerr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module.exports = function (_, dir, finish, gm) {
// The following invocation should fail, because 'convert'
// has no way of interpreting the file.
gm(
svg_file,
'./test.svg' // fiction
svg_file
).options({
imageMagick: true
}).setFormat('png').toBuffer(function(err, buffer) {
Expand Down

0 comments on commit 4301111

Please sign in to comment.