Prevent rounding err with shrink-on-load and 90/270 rot #1241

This commit is contained in:
Lovell Fuller
2018-06-19 21:19:34 +01:00
parent 09263455b5
commit da0b0348a2
4 changed files with 33 additions and 26 deletions

View File

@@ -177,25 +177,6 @@ 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)

View File

@@ -130,6 +130,25 @@ describe('Resize dimensions', function () {
});
});
it('JPEG shrink-on-load with 90 degree rotation, ensure recalculation is correct', function (done) {
sharp(fixtures.inputJpg)
.resize(1920, 1280)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(1920, info.width);
assert.strictEqual(1280, info.height);
sharp(data)
.rotate(90)
.resize(533, 800)
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(533, info.width);
assert.strictEqual(800, info.height);
done();
});
});
});
it('TIFF embed known to cause rounding errors', function (done) {
sharp(fixtures.inputTiff)
.resize(240, 320)