Prevent error when cumulative rounding below target #1154

This commit is contained in:
Lovell Fuller 2018-03-13 19:42:10 +00:00
parent 8f690236ed
commit f60f7dab12
3 changed files with 32 additions and 1 deletions

View File

@ -4,6 +4,12 @@
Requires libvips v8.6.1. Requires libvips v8.6.1.
#### v0.20.1 - TBD
* Prevent smartcrop error when cumulative rounding is below target size.
[#1154](https://github.com/lovell/sharp/issues/1154)
[@ralrom](https://github.com/ralrom)
#### v0.20.0 - 5<sup>th</sup> March 2018 #### v0.20.0 - 5<sup>th</sup> March 2018
* Add support for prebuilt sharp binaries on common platforms. * Add support for prebuilt sharp binaries on common platforms.

View File

@ -482,6 +482,12 @@ class PipelineWorker : public Nan::AsyncWorker {
image = image.extract_area(left, top, width, height); image = image.extract_area(left, top, width, height);
} else { } else {
// Attention-based or Entropy-based crop // Attention-based or Entropy-based crop
if (baton->width > image.width()) {
baton->width = image.width();
}
if (baton->height > image.height()) {
baton->height = image.height();
}
image = image.tilecache(VImage::option() image = image.tilecache(VImage::option()
->set("access", baton->accessMethod) ->set("access", baton->accessMethod)
->set("threaded", TRUE)); ->set("threaded", TRUE));

View File

@ -159,7 +159,7 @@ describe('Crop', function () {
}); });
}); });
it('Skip crop when post-resize dimensions are at or below target dimensions', function () { it('Skip crop when post-resize dimensions are at target', function () {
return sharp(fixtures.inputJpg) return sharp(fixtures.inputJpg)
.resize(1600, 1200) .resize(1600, 1200)
.toBuffer() .toBuffer()
@ -177,6 +177,25 @@ describe('Crop', function () {
}); });
}); });
it('Clamp before crop when one post-resize dimension is below target', function () {
return sharp(fixtures.inputJpg)
.resize(1024, 1034)
.toBuffer()
.then(function (input) {
return sharp(input)
.rotate(270)
.resize(256)
.crop(sharp.strategy.entropy)
.toBuffer({ resolveWithObject: true })
.then(function (result) {
assert.strictEqual(256, result.info.width);
assert.strictEqual(253, result.info.height);
assert.strictEqual(0, result.info.cropOffsetLeft);
assert.strictEqual(0, result.info.cropOffsetTop);
});
});
});
describe('Entropy-based strategy', function () { describe('Entropy-based strategy', function () {
it('JPEG', function (done) { it('JPEG', function (done) {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)