mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Fail fast for unknown interpolator
This commit is contained in:
parent
54f2243386
commit
46cc45c186
13
index.js
13
index.js
@ -317,7 +317,18 @@ module.exports.interpolator = {
|
|||||||
vertexSplitQuadraticBasisSpline: 'vsqbs'
|
vertexSplitQuadraticBasisSpline: 'vsqbs'
|
||||||
};
|
};
|
||||||
Sharp.prototype.interpolateWith = function(interpolator) {
|
Sharp.prototype.interpolateWith = function(interpolator) {
|
||||||
this.options.interpolator = interpolator;
|
var isValid = false;
|
||||||
|
for (var key in module.exports.interpolator) {
|
||||||
|
if (module.exports.interpolator[key] === interpolator) {
|
||||||
|
isValid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isValid) {
|
||||||
|
this.options.interpolator = interpolator;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid interpolator ' + interpolator);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,15 +94,13 @@ describe('Interpolation', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('unknown interpolator throws', function(done) {
|
it('unknown interpolator throws', function(done) {
|
||||||
sharp(fixtures.inputJpg)
|
var isValid = false;
|
||||||
.resize(320, 240)
|
try {
|
||||||
.interpolateWith('nonexistant')
|
sharp().interpolateWith('nonexistant');
|
||||||
.toBuffer()
|
isValid = true;
|
||||||
.catch(function (e) {
|
} catch (e) {}
|
||||||
assert(
|
assert(!isValid);
|
||||||
e.toString().match(/VipsInterpolate: class "nonexistant" not found/)
|
done();
|
||||||
);
|
|
||||||
})
|
|
||||||
.finally(done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -34,7 +34,7 @@ describe('Normalization', function () {
|
|||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.gamma()
|
.gamma()
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.normalize()
|
.normalize(true)
|
||||||
.raw()
|
.raw()
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user