diff --git a/lib/resize.js b/lib/resize.js index 34a7e74b..d77add63 100644 --- a/lib/resize.js +++ b/lib/resize.js @@ -36,6 +36,7 @@ const strategy = { * @private */ const kernel = { + nearest: 'nearest', cubic: 'cubic', lanczos2: 'lanczos2', lanczos3: 'lanczos3' @@ -62,6 +63,7 @@ const interpolator = { * By default, the resized image is centre cropped to the exact size specified. * * Possible reduction kernels are: + * - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation). * - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline). * - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`. * - `lanczos3`: Use a Lanczos kernel with `a=3` (the default). diff --git a/src/pipeline.cc b/src/pipeline.cc index e8034091..50a95fd2 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -392,7 +392,10 @@ class PipelineWorker : public Nan::AsyncWorker { if (yresidual < 1.0 || xresidual < 1.0) { VipsKernel kernel = static_cast( vips_enum_from_nick(nullptr, VIPS_TYPE_KERNEL, baton->kernel.data())); - if (kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 && kernel != VIPS_KERNEL_LANCZOS3) { + if ( + kernel != VIPS_KERNEL_NEAREST && kernel != VIPS_KERNEL_CUBIC && kernel != VIPS_KERNEL_LANCZOS2 && + kernel != VIPS_KERNEL_LANCZOS3 + ) { throw vips::VError("Unknown kernel"); } if (yresidual < 1.0) { diff --git a/test/unit/interpolation.js b/test/unit/interpolation.js index 2db8aa43..ab964168 100644 --- a/test/unit/interpolation.js +++ b/test/unit/interpolation.js @@ -8,6 +8,7 @@ const fixtures = require('../fixtures'); describe('Interpolators and kernels', function () { describe('Reducers', function () { [ + sharp.kernel.nearest, sharp.kernel.cubic, sharp.kernel.lanczos2, sharp.kernel.lanczos3