Skip to content

Commit

Permalink
Update to sharp 0.12, minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseventer committed Jan 26, 2016
1 parent 1f66e20 commit 6fa5c11
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.

Expand Down
2 changes: 2 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var cli = meow(help, {
'ignoreAspectRatio',
'max',
'min',
'negate',
'normalize',
'optimizeScans',
'overshootDeringing',
Expand Down Expand Up @@ -87,6 +88,7 @@ var cli = meow(help, {
'sharpen',
'sharpenFlat',
'sharpenJagged',
'threshold',
'tile',
'tileOverlap',
'width'
Expand Down
8 changes: 5 additions & 3 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ Options
--help Output usage information.
--ignoreAspectRatio Stretch the image to the exact width and/or height specified.
--interpolateWith <string> Use the specified interpolator (nearest, bilinear, bicubic,
vertexSplitQuadraticBasisSpline, locallyBoundedBicubic, nohalo) for
image resizing.
vertexSplitQuadraticBasisSpline (vsqbs), locallyBoundedBicubic (lbb),
nohalo) for image resizing.
--limitInputPixels <number> 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
dimensions are less than or equal to the specified width and height.
--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 <string> The output filename, or directory when performing batch operations.
--optimizeScans, --optimiseScans
Expand All @@ -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 <number> Sharpen the output image, optionally specifying the sharpen radius.
--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
to 2.0. Use in conjunction with --sharpen.
--threshold <number> 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 <number> Specifies the tile overlap, between 0 and 8192. Defaults to 0 pixels.
Expand Down
13 changes: 12 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,19 @@ 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
if(flags.background) {
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();
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
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.
84 changes: 73 additions & 11 deletions test/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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([ 10, 1, 1, 1 ]);
expect(spy.args[0]).to.eql([{
top : 10,
left : 1,
width : 1,
height : 1
}]);
});
});
it('--extractTop <number> (invalid value)', function() {
Expand All @@ -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');
});
Expand All @@ -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 <number> (invalid value)', function() {
Expand All @@ -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');
});
Expand All @@ -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 <number> (invalid value)', function() {
Expand All @@ -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');
});
Expand All @@ -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 <number> (invalid value)', function() {
Expand All @@ -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');
});
Expand Down Expand Up @@ -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 <string>', function() {
this.flags.output = outputTest;
Expand Down Expand Up @@ -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 <number> (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;
Expand Down

0 comments on commit 6fa5c11

Please sign in to comment.