diff --git a/CHANGELOG.md b/CHANGELOG.md index 601c484..503a493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.5.0 (June 21, 2016) +* Enhancement: add [`--kernel`](http://sharp.dimens.io/en/stable/api/#resizewidth-height-options). +* Enhancement: rename `--interpolateWith` to [`--interpolator`](http://sharp.dimens.io/en/stable/api/#resizewidth-height-options). + ## 0.4.2 (June 21, 2016) * Bugfix: mark `--grayscale` as boolean option. * Enhancement: update dependencies, including `sharp` (`0.15.x`). diff --git a/README.md b/README.md index aa802e2..6f74522 100644 --- a/README.md +++ b/README.md @@ -55,10 +55,13 @@ $ sharp --help --grayscale, --greyscale Convert to grayscale. -h, --height Scale output to height. --help Output usage information. + --kernel Kernel to use for image reduction (cubic, lanczo2, lanczo3). Defaults + to lanczo3. Use in conjunction with --width or --height. --ignoreAspectRatio Stretch the image to the exact width and/or height specified. - --interpolateWith Use the specified interpolator (nearest, bilinear, bicubic, + --interpolator Use the specified interpolator (nearest, bilinear, bicubic, vertexSplitQuadraticBasisSpline (vsqbs), locallyBoundedBicubic (lbb), - nohalo) for image resizing. + nohalo) for image resizing. Use in conjunction with --width or + --height. --limitInputPixels Do not process input images where the number of pixels (width × height) exceeds the specified amount. --max Resize the image to be as large as possible while ensuring its diff --git a/help.txt b/help.txt index e4ba8bc..a5a38f3 100644 --- a/help.txt +++ b/help.txt @@ -41,10 +41,13 @@ Options --grayscale, --greyscale Convert to grayscale. -h, --height Scale output to height. --help Output usage information. + --kernel Kernel to use for image reduction (cubic, lanczo2, lanczo3). Defaults + to lanczo3. Use in conjunction with --width or --height. --ignoreAspectRatio Stretch the image to the exact width and/or height specified. - --interpolateWith Use the specified interpolator (nearest, bilinear, bicubic, + --interpolator Use the specified interpolator (nearest, bilinear, bicubic, vertexSplitQuadraticBasisSpline (vsqbs), locallyBoundedBicubic (lbb), - nohalo) for image resizing. + nohalo) for image resizing. Use in conjunction with --width or + --height. --limitInputPixels Do not process input images where the number of pixels (width × height) exceeds the specified amount. --max Resize the image to be as large as possible while ensuring its diff --git a/lib/runner.js b/lib/runner.js index c63d2bf..e7ade61 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -57,12 +57,12 @@ var run = function(src, flags) { // Resize options. // =============== - // @see http://sharp.dimens.io/en/stable/api/#resizewidth-height + // @see http://sharp.dimens.io/en/stable/api/#resizewidth-height-options if(flags.height || flags.width) { - // NOTE: Sharp deals with NaN when width or height are not specified. var width = parseInt(flags.width, 10) || null, - height = parseInt(flags.height, 10) || null; - image.resize(width, height); + height = parseInt(flags.height, 10) || null, + opts = { interpolator: flags.interpolator, kernel: flags.kernel }; + image.resize(width, height, opts); } // @see http://sharp.dimens.io/en/stable/api/#cropgravity @@ -95,11 +95,6 @@ var run = function(src, flags) { image.ignoreAspectRatio(); } - // @see http://sharp.dimens.io/en/stable/api/#interpolatewithinterpolator - if(flags.interpolateWith) { - image.interpolateWith(flags.interpolateWith); - } - // Operations. // ============ diff --git a/package.json b/package.json index d5856d1..649a28b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "sharp-cli", - "version" : "0.4.2", + "version" : "0.5.0", "description" : "CLI for sharp.", "keywords" : [ "cli", "jpeg", "libvips", "png", "sharp", "vips", "webp" ], "homepage" : "https://github.com/vseventer/sharp-cli", diff --git a/test/fixtures/input.jpg b/test/fixtures/input.jpg index 7049860..4df0e1e 100644 Binary files a/test/fixtures/input.jpg and b/test/fixtures/input.jpg differ diff --git a/test/runner.test.js b/test/runner.test.js index 66d4f74..194bb33 100644 --- a/test/runner.test.js +++ b/test/runner.test.js @@ -565,7 +565,7 @@ 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([ null, 100 ]); + expect(spy.args[0]).to.eql([ null, 100, { interpolator: undefined, kernel: undefined } ]); }); }); it('--height (invalid value)', function() { @@ -573,33 +573,70 @@ 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([ null, null ]); + expect(spy.args[0]).to.eql([ null, null, { interpolator: undefined, kernel: undefined } ]); }); }); it('--ignoreAspectRatio', testBoolean('ignoreAspectRatio')); - it('--interpolateWith ', function() { - var spy = this.spyOn('interpolateWith'); - this.flags.interpolateWith = 'bilinear'; + it('--interpolator ', function() { + var spy = this.spyOn('resize'); + this.flags.width = 100; + this.flags.interpolator = 'bilinear'; return runner.run(input, this.flags).then(function() { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 'bilinear' ]); + expect(spy.args[0]).to.eql([ 100, null, { + interpolator: 'bilinear', + kernel: undefined + } ]); }); }); - it('--interpolateWith (invalid value)', function() { - var spy = this.spyOn('interpolateWith'); - this.flags.interpolateWith = 'foo'; + it('--interpolator (invalid value)', function() { + var spy = this.spyOn('resize'); + this.flags.width = 100; + this.flags.interpolator = 'foo'; return runner.run(input, this.flags).then(function() { throw new Error('TRIGGER REJECTION'); }).catch(function(err) { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 'foo' ]); + expect(spy.args[0]).to.eql([ 100, null, { + interpolator: 'foo', + kernel: undefined + } ]); expect(err).to.have.property('message'); expect(err.message.toLowerCase()).to.contain('invalid interpolator'); }); }); + it('--kernel ', function() { + var spy = this.spyOn('resize'); + this.flags.width = 100; + this.flags.kernel = 'cubic'; + return runner.run(input, this.flags).then(function() { + expect(spy).to.be.calledOnce; + expect(spy.args[0]).to.eql([ 100, null, { + interpolator: undefined, + kernel: 'cubic' + } ]); + }); + }); + it('--kernel (invalid value)', function() { + var spy = this.spyOn('resize'); + this.flags.width = 100; + this.flags.kernel = 'foo'; + return runner.run(input, this.flags).then(function() { + throw new Error('TRIGGER REJECTION'); + }).catch(function(err) { + expect(spy).to.be.calledOnce; + expect(spy.args[0]).to.eql([ 100, null, { + interpolator: undefined, + kernel: 'foo' + } ]); + expect(err).to.have.property('message'); + expect(err.message.toLowerCase()).to.contain('invalid kernel'); + }); + }); + it('--limitInputPixels ', function() { var spy = this.spyOn('limitInputPixels'); this.flags.limitInputPixels = '100000'; @@ -941,7 +978,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, null ]); + expect(spy.args[0]).to.eql([ 100, null, { interpolator: undefined, kernel: undefined } ]); }); }); it('--width (invalid value)', function() { @@ -949,7 +986,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([ null, null ]); + expect(spy.args[0]).to.eql([ null, null, { interpolator: undefined, kernel: undefined } ]); }); });