Skip to content

Commit

Permalink
Fix grayscale bug, changes due to sharp update.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseventer committed Jun 21, 2016
1 parent a482ba3 commit e6bf599
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var cli = meow(help, {
'flatten',
'flip',
'flop',
'greyscale',
'help',
'ignoreAspectRatio',
'max',
Expand Down
2 changes: 1 addition & 1 deletion help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Options
--rotate [number] Rotate the output image by the specified angle (0, 90, 180, 270), or
auto-orient based on the EXIF Orientation tag.
--sequentialRead Switches the libvips access method to VIPS_ACCESS_SEQUENTIAL.
--sharpen <number> Sharpen the output image, optionally specifying the sharpen radius.
--sharpen <number> Sharpen the output image, optionally specifying the sharpen sigma.
--sharpenFlat <number> Specify the level of sharpeness to apply to "flat" areas. Defaults to
1.0. Use in conjunction with --sharpen.
--sharpenJagged <number> Specify the level of sharpeness to apply to "jagged" areas. Defaults
Expand Down
14 changes: 7 additions & 7 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var run = function(src, flags) {
// @see http://sharp.dimens.io/en/stable/api/#resizewidth-height
if(flags.height || flags.width) {
// NOTE: Sharp deals with NaN when width or height are not specified.
var width = parseInt(flags.width, 10),
height = parseInt(flags.height, 10);
var width = parseInt(flags.width, 10) || null,
height = parseInt(flags.height, 10) || null;
image.resize(width, height);
}

Expand Down Expand Up @@ -157,16 +157,16 @@ var run = function(src, flags) {
image.blur();
}
else if(flags.blur) {
var sigma = parseFloat(flags.blur);
image.blur(sigma);
var blurSigma = parseFloat(flags.blur);
image.blur(blurSigma);
}

// @see http://sharp.dimens.io/en/stable/api/#sharpenradius-flat-jagged
// @see http://sharp.dimens.io/en/stable/api/#sharpensigma-flat-jagged
if(flags.sharpen || flags.sharpenFlat || flags.sharpenJagged) {
var radius = true === flags.sharpen ? undefined : parseInt(flags.sharpen, 10),
var sigma = true === flags.sharpen ? undefined : parseInt(flags.sharpen, 10),
flat = flags.sharpenFlat ? parseFloat(flags.sharpenFlat) : undefined,
jagged = flags.sharpenJagged ? parseFloat(flags.sharpenJagged) : undefined;
image.sharpen(radius, flat, jagged);
image.sharpen(sigma, flat, jagged);
}

// @see http://sharp.dimens.io/en/stable/api/#thresholdthreshold
Expand Down
Binary file modified test/fixtures/input.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions test/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,15 @@ describe('runner', function() {
this.flags.height = 100;
return runner.run(input, this.flags).then(function() {
expect(spy).to.be.calledOnce;
expect(spy.args[0]).to.eql([ NaN, 100 ]);
expect(spy.args[0]).to.eql([ null, 100 ]);
});
});
it('--height <number> (invalid value)', function() {
var spy = this.spyOn('resize');
this.flags.height = 'foo';
return runner.run(input, this.flags).then(function() {
expect(spy).to.be.calledOnce;
expect(spy.args[0]).to.eql([ NaN, NaN ]);
expect(spy.args[0]).to.eql([ null, null ]);
});
});

Expand Down Expand Up @@ -770,7 +770,7 @@ describe('runner', function() {
expect(spy).to.be.calledOnce;
expect(spy.args[0]).to.eql([ NaN, undefined, undefined ]);
expect(err).to.have.property('message');
expect(err.message.toLowerCase()).to.contain('invalid sharpen radius');
expect(err.message.toLowerCase()).to.contain('invalid sharpen sigma');
});
});
it('--sharpenFlat <number>', function() {
Expand Down Expand Up @@ -941,15 +941,15 @@ describe('runner', function() {
this.flags.width = 100;
return runner.run(input, this.flags).then(function() {
expect(spy).to.be.calledOnce;
expect(spy.args[0]).to.eql([ 100, NaN ]);
expect(spy.args[0]).to.eql([ 100, null ]);
});
});
it('--width <number> (invalid value)', function() {
var spy = this.spyOn('resize');
this.flags.width = 'foo';
return runner.run(input, this.flags).then(function() {
expect(spy).to.be.calledOnce;
expect(spy.args[0]).to.eql([ NaN, NaN ]);
expect(spy.args[0]).to.eql([ null, null ]);
});
});

Expand Down

0 comments on commit e6bf599

Please sign in to comment.