mirror of
https://github.com/lovell/sharp.git
synced 2025-07-11 19:40:14 +02:00
Ensure shortest resized edge is >= 1px #1003
This commit is contained in:
parent
f5d3721fe0
commit
7c631c0787
@ -6,6 +6,9 @@ Requires libvips v8.7.0.
|
||||
|
||||
#### v0.21.2 - TBD
|
||||
|
||||
* Ensure shortest edge is at least one pixel after resizing.
|
||||
[#1003](https://github.com/lovell/sharp/issues/1003)
|
||||
|
||||
* Expose `pages` and `pageHeight` metadata for multi-page input images.
|
||||
[#1205](https://github.com/lovell/sharp/issues/1205)
|
||||
|
||||
|
@ -385,6 +385,15 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
) {
|
||||
throw vips::VError("Unknown kernel");
|
||||
}
|
||||
// Ensure shortest edge is at least 1 pixel
|
||||
if (image.width() / xfactor < 0.5) {
|
||||
xfactor = 2 * image.width();
|
||||
baton->width = 1;
|
||||
}
|
||||
if (image.height() / yfactor < 0.5) {
|
||||
yfactor = 2 * image.height();
|
||||
baton->height = 1;
|
||||
}
|
||||
image = image.resize(1.0 / xfactor, VImage::option()
|
||||
->set("vscale", 1.0 / yfactor)
|
||||
->set("kernel", kernel));
|
||||
|
@ -525,6 +525,40 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Ensure shortest edge (height) is at least 1 pixel', function () {
|
||||
return sharp({
|
||||
create: {
|
||||
width: 10,
|
||||
height: 2,
|
||||
channels: 3,
|
||||
background: 'red'
|
||||
}
|
||||
})
|
||||
.resize(2)
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (output) {
|
||||
assert.strictEqual(2, output.info.width);
|
||||
assert.strictEqual(1, output.info.height);
|
||||
});
|
||||
});
|
||||
|
||||
it('Ensure shortest edge (width) is at least 1 pixel', function () {
|
||||
return sharp({
|
||||
create: {
|
||||
width: 2,
|
||||
height: 10,
|
||||
channels: 3,
|
||||
background: 'red'
|
||||
}
|
||||
})
|
||||
.resize(null, 2)
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(function (output) {
|
||||
assert.strictEqual(1, output.info.width);
|
||||
assert.strictEqual(2, output.info.height);
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown kernel throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp().resize(null, null, { kernel: 'unknown' });
|
||||
|
Loading…
x
Reference in New Issue
Block a user