Add nearest neighbour interpolation

Suitable for image enlargement
This commit is contained in:
Lovell Fuller
2014-08-26 09:38:27 +01:00
parent d0f51363bf
commit 8380be4be3
5 changed files with 28 additions and 4 deletions

View File

@@ -185,6 +185,18 @@ async.series({
}
});
}
}).add("sharp-file-buffer-nearest-neighbour", {
defer: true,
fn: function(deferred) {
sharp(inputJpg).resize(width, height).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, buffer) {
if (err) {
throw err;
} else {
assert.notStrictEqual(null, buffer);
deferred.resolve();
}
});
}
}).add("sharp-file-buffer-bicubic", {
defer: true,
fn: function(deferred) {

View File

@@ -247,6 +247,16 @@ async.series([
done();
});
},
// Interpolation: nearest neighbour
function(done) {
sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.nearest).toBuffer(function(err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
done();
});
},
// Interpolation: bilinear
function(done) {
sharp(inputJpg).resize(320, 240).interpolateWith(sharp.interpolator.bilinear).toBuffer(function(err, data, info) {