mirror of
https://github.com/lovell/sharp.git
synced 2025-07-10 19:10:14 +02:00
Prevent error when cumulative rounding below target #1154
This commit is contained in:
parent
8f690236ed
commit
f60f7dab12
@ -4,6 +4,12 @@
|
||||
|
||||
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
|
||||
|
||||
* Add support for prebuilt sharp binaries on common platforms.
|
||||
|
@ -482,6 +482,12 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
image = image.extract_area(left, top, width, height);
|
||||
} else {
|
||||
// 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()
|
||||
->set("access", baton->accessMethod)
|
||||
->set("threaded", TRUE));
|
||||
|
@ -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)
|
||||
.resize(1600, 1200)
|
||||
.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 () {
|
||||
it('JPEG', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
|
Loading…
x
Reference in New Issue
Block a user