Keep output dimensions within WebP 14-bit range

This commit is contained in:
Lovell Fuller
2014-12-06 22:33:47 +00:00
parent 065ce6454b
commit 464fb1726d
4 changed files with 52 additions and 8 deletions

View File

@@ -176,7 +176,7 @@ describe('Image metadata', function() {
assert.strictEqual(3, metadata.channels);
assert.strictEqual(false, metadata.hasProfile);
assert.strictEqual(false, metadata.hasAlpha);
image.resize(metadata.width / 2).toBuffer(function(err, data, info) {
image.resize(Math.floor(metadata.width / 2)).toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual(1362, info.width);

View File

@@ -64,7 +64,7 @@ describe('Resize dimensions', function() {
});
});
it('Invalid width', function(done) {
it('Invalid width - NaN', function(done) {
var isValid = true;
try {
sharp(fixtures.inputJpg).resize('spoons', 240);
@@ -75,7 +75,7 @@ describe('Resize dimensions', function() {
done();
});
it('Invalid height', function(done) {
it('Invalid height - NaN', function(done) {
var isValid = true;
try {
sharp(fixtures.inputJpg).resize(320, 'spoons');
@@ -86,6 +86,50 @@ describe('Resize dimensions', function() {
done();
});
it('Invalid width - float', function(done) {
var isValid = true;
try {
sharp(fixtures.inputJpg).resize(1.5, 240);
} catch (err) {
isValid = false;
}
assert.strictEqual(false, isValid);
done();
});
it('Invalid height - float', function(done) {
var isValid = true;
try {
sharp(fixtures.inputJpg).resize(320, 1.5);
} catch (err) {
isValid = false;
}
assert.strictEqual(false, isValid);
done();
});
it('Invalid width - too large', function(done) {
var isValid = true;
try {
sharp(fixtures.inputJpg).resize(0x4000, 240);
} catch (err) {
isValid = false;
}
assert.strictEqual(false, isValid);
done();
});
it('Invalid height - too large', function(done) {
var isValid = true;
try {
sharp(fixtures.inputJpg).resize(320, 0x4000);
} catch (err) {
isValid = false;
}
assert.strictEqual(false, isValid);
done();
});
it('TIFF embed known to cause rounding errors', function(done) {
sharp(fixtures.inputTiff).resize(240, 320).embed().jpeg().toBuffer(function(err, data, info) {
if (err) throw err;