From 6fa5c119f01cd844ce6269bcfabbb68a1b160998 Mon Sep 17 00:00:00 2001 From: vseventer Date: Tue, 26 Jan 2016 19:34:49 +1100 Subject: [PATCH] Update to sharp 0.12, minor changes. --- CHANGELOG.md | 5 +++ cli.js | 2 + help.txt | 8 ++-- lib/runner.js | 13 ++++++- package.json | 14 +++---- test/fixtures/input.jpg | Bin 2891 -> 2871 bytes test/runner.test.js | 84 ++++++++++++++++++++++++++++++++++------ 7 files changed, 104 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb7936d..73c314f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 0.3.0 (January 26, 2016) +* Enhancement: add [`--negate`](http://sharp.dimens.io/en/stable/api/#negate) support. +* Enhancement: add [`--threshold`](http://sharp.dimens.io/en/stable/api/#thresholdthreshold) support. +* Enhancement: update dependencies, including `sharp` (`0.12.x`). + ## 0.2.2 (January 13, 2016) * Enhancement: process multiple files in batches of `25`. diff --git a/cli.js b/cli.js index 5402ce6..b037d78 100755 --- a/cli.js +++ b/cli.js @@ -53,6 +53,7 @@ var cli = meow(help, { 'ignoreAspectRatio', 'max', 'min', + 'negate', 'normalize', 'optimizeScans', 'overshootDeringing', @@ -87,6 +88,7 @@ var cli = meow(help, { 'sharpen', 'sharpenFlat', 'sharpenJagged', + 'threshold', 'tile', 'tileOverlap', 'width' diff --git a/help.txt b/help.txt index f9631a7..12683f9 100644 --- a/help.txt +++ b/help.txt @@ -35,8 +35,8 @@ Options --help Output usage information. --ignoreAspectRatio Stretch the image to the exact width and/or height specified. --interpolateWith Use the specified interpolator (nearest, bilinear, bicubic, - vertexSplitQuadraticBasisSpline, locallyBoundedBicubic, nohalo) for - image resizing. + vertexSplitQuadraticBasisSpline (vsqbs), locallyBoundedBicubic (lbb), + nohalo) for image resizing. --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 @@ -44,6 +44,7 @@ Options --min Resize the image to be as small as possible while ensuring its dimensions are greater than or equal to the specified width and height. + --negate Produces the negative of the image. --normalize, --normalise Enhance output image contrast. -o, --output The output filename, or directory when performing batch operations. --optimizeScans, --optimiseScans @@ -57,11 +58,12 @@ 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 Sharpen the output image, optionally specifying the sharpen radius. --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 to 2.0. Use in conjunction with --sharpen. + --threshold Specify the level above which pixels will be forced to white. --tile [number] Applies square image pyramid tiles over the image, optionally specifying a tile size between 1 and 8192. Defaults to 256 pixels. --tileOverlap Specifies the tile overlap, between 0 and 8192. Defaults to 0 pixels. diff --git a/lib/runner.js b/lib/runner.js index 1adb015..c87308c 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -109,7 +109,7 @@ var run = function(src, flags) { left = parseInt(flags.extractLeft, 10), eWidth = parseInt(flags.extractWidth, 10), eHeight = parseInt(flags.extractHeight, 10); - image.extract(top, left, eWidth, eHeight); + image.extract({ top: top, left: left, width: eWidth, height: eHeight }); } // @see http://sharp.dimens.io/en/stable/api/#backgroundrgba @@ -117,6 +117,11 @@ var run = function(src, flags) { image.background(flags.background); } + // @see http://sharp.dimens.io/en/stable/api/#negate + if(flags.negate) { + image.negate(); + } + // @see http://sharp.dimens.io/en/stable/api/#flatten if(flags.flatten) { image.flatten(); @@ -155,6 +160,12 @@ var run = function(src, flags) { image.sharpen(radius, flat, jagged); } + // @see http://sharp.dimens.io/en/stable/api/#thresholdthreshold + if(flags.threshold) { + var threshold = parseInt(flags.threshold, 10); + image.threshold(threshold); + } + // @see http://sharp.dimens.io/en/stable/api/#gammagamma if(true === flags.gamma) { image.gamma(); diff --git a/package.json b/package.json index 5956490..32d924a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "sharp-cli", - "version" : "0.2.2", + "version" : "0.3.0", "description" : "CLI for sharp.", "keywords" : [ "cli", "jpeg", "libvips", "png", "sharp", "vips", "webp" ], "homepage" : "https://github.com/vseventer/sharp-cli", @@ -14,18 +14,18 @@ "test" : "mocha" }, "dependencies": { - "bluebird" : "3.0.x", - "glob" : "5.0.x", + "bluebird" : "3.1.x", + "glob" : "6.0.x", "is-file" : "1.0.x", - "meow" : "3.5.x", + "meow" : "3.7.x", "mkdir-p" : "0.0.x", - "sharp" : "0.11.x", + "sharp" : "0.12.x", "sponge" : "0.1.x" }, "devDependencies": { "chai" : "3.4.x", - "jshint" : "2.8.x", - "jshint-stylish": "2.0.x", + "jshint" : "2.9.x", + "jshint-stylish": "2.1.x", "mocha" : "2.3.x", "sinon" : "1.17.x", "sinon-chai" : "2.8.x" diff --git a/test/fixtures/input.jpg b/test/fixtures/input.jpg index 3e5b985bf85c07ea2cb3a686ec37bd4b97bc5820..88f6b40c29f8a8f2d5902ed8649b9771ef1fccea 100644 GIT binary patch delta 357 zcmV-r0h<2H7Pl4x|Jbn<-U)vf?Q=8xNYXnNeJ|oCC+kvP)%fow*W&%q>%VbHsiZ!X z#z?k`7m7Q(sR<==nuy0uBRM`tYG6EzV+d_5#As2C)NO<3QohNm^JCb1joZ?oCHKGQ ztvddQ!=Z_JEiiCQc?=HQ`3!ZZT2vZl*eL~B4^G>4{7pGO_H2Lk8~uLiy$e%MK7##~fL2nh4fLU3p*>_sEO`Tu2Oe&Vxu53_;c_z zHVOUy=ie1T;!NC?@g7Fh9XZ_Ca?%}}3xS%5 zwPyP|c#nSn02-5tn?yb%(08ZQ(KnTWOLkZTtHe)MHI#My5pxgjliwe7R#i1FhO__K DC~vf1 delta 377 zcmV-<0fzp!7RweC|JeWF01!$>Nk#wx0RR9200961u>#%+e--U3Gx7G3*t6+>5jj6v zllF_pc{aZn?uT9bicL)+^rkXJv{1ZJ-Q7q@E0okmI%yfn@;g%jslk{{TH{*Yrjm3`@yrgMwqoV0PcgW34*Upwl+NNGiyBcH6Jw zY03Wpvt$1Nf2iN+HCAcn`$zF)_gC*4-dJ#gt~lb$e9%U+GV99#r^EE>aZ+gZ%Myl{ zPRztGJ$rR0vFJRgZWr#w{(s2Oa;l}IS`;sUbQtrdaZS)CQEU$Ph}uU9X&NIhRNFd6 zPRBoAokUM^jdGK_qZJtem&2cdsUT19_dfWlPZDP2Td#=s@A0ceX>^V$c@kxxn)3Mh zsub_nrZ%YlAnDHL! (invalid value)', function() { @@ -242,7 +247,12 @@ describe('runner', function() { throw new Error('TRIGGER REJECTION'); }).catch(function(err) { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ NaN, 1, 1, 1 ]); + expect(spy.args[0]).to.eql([{ + top : NaN, + left : 1, + width : 1, + height : 1 + }]); expect(err).to.have.property('message'); expect(err.message.toLowerCase()).to.contain('non-integer value for top'); }); @@ -255,7 +265,12 @@ describe('runner', function() { this.flags.extractHeight = '1'; return runner.run(input, this.flags).then(function() { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 1, 10, 1, 1 ]); + expect(spy.args[0]).to.eql([{ + top : 1, + left : 10, + width : 1, + height : 1 + }]); }); }); it('--extractLeft (invalid value)', function() { @@ -268,7 +283,12 @@ describe('runner', function() { throw new Error('TRIGGER REJECTION'); }).catch(function(err) { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 1, NaN, 1, 1 ]); + expect(spy.args[0]).to.eql([{ + top : 1, + left : NaN, + width : 1, + height : 1 + }]); expect(err).to.have.property('message'); expect(err.message.toLowerCase()).to.contain('non-integer value for left'); }); @@ -281,7 +301,12 @@ describe('runner', function() { this.flags.extractHeight = '1'; return runner.run(input, this.flags).then(function() { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 1, 1, 10, 1 ]); + expect(spy.args[0]).to.eql([{ + top : 1, + left : 1, + width : 10, + height : 1 + }]); }); }); it('--extractWidth (invalid value)', function() { @@ -294,7 +319,12 @@ describe('runner', function() { throw new Error('TRIGGER REJECTION'); }).catch(function(err) { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 1, 1, NaN, 1 ]); + expect(spy.args[0]).to.eql([{ + top : 1, + left : 1, + width : NaN, + height : 1 + }]); expect(err).to.have.property('message'); expect(err.message.toLowerCase()).to.contain('non-integer value for width'); }); @@ -307,7 +337,12 @@ describe('runner', function() { this.flags.extractWidth = '1'; return runner.run(input, this.flags).then(function() { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 1, 1, 1, 10 ]); + expect(spy.args[0]).to.eql([{ + top : 1, + left : 1, + width : 1, + height : 10 + }]); }); }); it('--extractHeight (invalid value)', function() { @@ -320,7 +355,12 @@ describe('runner', function() { throw new Error('TRIGGER REJECTION'); }).catch(function(err) { expect(spy).to.be.calledOnce; - expect(spy.args[0]).to.eql([ 1, 1, 1, NaN ]); + expect(spy.args[0]).to.eql([{ + top : 1, + left : 1, + width : 1, + height : NaN + }]); expect(err).to.have.property('message'); expect(err.message.toLowerCase()).to.contain('non-integer value for height'); }); @@ -436,9 +476,10 @@ describe('runner', function() { }); }); - it('--max', testBoolean('max')); - it('--max', testBoolean('min')); - it('--max', testBoolean('normalize')); + it('--max', testBoolean('max')); + it('--min', testBoolean('min')); + it('--normalize', testBoolean('normalize')); + it('--negate', testBoolean('negate')); it('--output ', function() { this.flags.output = outputTest; @@ -610,6 +651,27 @@ describe('runner', function() { }); }); + it('--threshold', function() { + var spy = this.spyOn('threshold'); + this.flags.threshold = '1'; + return runner.run(input, this.flags).then(function() { + expect(spy).to.be.calledOnce; + expect(spy.args[0]).to.eql([ 1 ]); + }); + }); + it('--threshold (invalid value).', function() { + var spy = this.spyOn('threshold'); + this.flags.threshold = '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([ NaN ]); + expect(err).to.have.property('message'); + expect(err.message.toLowerCase()).to.contain('invalid threshold'); + }); + }); + it('--tile', function() { var spy = this.spyOn('tile'); this.flags.tile = true;