From e6bf599cc608b525195f5eb704491e29f0a09064 Mon Sep 17 00:00:00 2001 From: vseventer Date: Tue, 21 Jun 2016 19:16:13 +0200 Subject: [PATCH] Fix grayscale bug, changes due to sharp update. --- cli.js | 1 + help.txt | 2 +- lib/runner.js | 14 +++++++------- test/fixtures/input.jpg | Bin 2873 -> 2873 bytes test/runner.test.js | 10 +++++----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cli.js b/cli.js index 1439f21..e305ade 100755 --- a/cli.js +++ b/cli.js @@ -49,6 +49,7 @@ var cli = meow(help, { 'flatten', 'flip', 'flop', + 'greyscale', 'help', 'ignoreAspectRatio', 'max', diff --git a/help.txt b/help.txt index 105211f..e4ba8bc 100644 --- a/help.txt +++ b/help.txt @@ -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 Sharpen the output image, optionally specifying the sharpen radius. + --sharpen Sharpen the output image, optionally specifying the sharpen sigma. --sharpenFlat Specify the level of sharpeness to apply to "flat" areas. Defaults to 1.0. Use in conjunction with --sharpen. --sharpenJagged Specify the level of sharpeness to apply to "jagged" areas. Defaults diff --git a/lib/runner.js b/lib/runner.js index 515fe7b..c63d2bf 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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); } @@ -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 diff --git a/test/fixtures/input.jpg b/test/fixtures/input.jpg index 7960d6997599f0e29fc741d465641f2809f979b6..7049860da1d651111fe4356d9f67df3ea68a41a7 100644 GIT binary patch delta 46 zcmV+}0MY-s7P%I%$p8QV delta 46 zcmV+}0MY-s7P%I% (invalid value)', function() { @@ -573,7 +573,7 @@ describe('runner', function() { 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 ]); }); }); @@ -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 ', function() { @@ -941,7 +941,7 @@ 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 (invalid value)', function() { @@ -949,7 +949,7 @@ describe('runner', function() { 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 ]); }); });