From 9392b8702bb6895c3951180f7125d7eff80885fb Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 15 Jun 2025 12:53:10 +0100 Subject: [PATCH] Add Magic Kernel Sharp (no relation) to resizing kernels --- docs/src/content/docs/api-resize.md | 2 ++ docs/src/content/docs/changelog.md | 2 ++ lib/index.d.ts | 2 ++ lib/resize.js | 2 ++ test/types/sharp.test-d.ts | 2 ++ 5 files changed, 10 insertions(+) diff --git a/docs/src/content/docs/api-resize.md b/docs/src/content/docs/api-resize.md index da7ac53b..6452c345 100644 --- a/docs/src/content/docs/api-resize.md +++ b/docs/src/content/docs/api-resize.md @@ -38,6 +38,8 @@ Possible downsizing kernels are: - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf). - `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). +- `mks2013`: Use a [Magic Kernel Sharp](https://johncostella.com/magic/mks.pdf) 2013 kernel, as adopted by Facebook. +- `mks2021`: Use a Magic Kernel Sharp 2021 kernel, with more accurate (reduced) sharpening than the 2013 version. When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators. Downsampling kernels without a matching upsampling interpolator map to `cubic`. diff --git a/docs/src/content/docs/changelog.md b/docs/src/content/docs/changelog.md index f84859d8..88c82293 100644 --- a/docs/src/content/docs/changelog.md +++ b/docs/src/content/docs/changelog.md @@ -10,6 +10,8 @@ Requires libvips v8.17.0 * Upgrade to libvips v8.17.0 for upstream bug fixes. +* Add "Magic Kernel Sharp" (no relation) to resizing kernels. + * Expose JPEG 2000 `oneshot` decoder option. [#4262](https://github.com/lovell/sharp/pull/4262) [@mbklein](https://github.com/mbklein) diff --git a/lib/index.d.ts b/lib/index.d.ts index 9ed7190d..2d93ac84 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1729,6 +1729,8 @@ declare namespace sharp { mitchell: 'mitchell'; lanczos2: 'lanczos2'; lanczos3: 'lanczos3'; + mks2013: 'mks2013'; + mks2021: 'mks2021'; } interface PresetEnum { diff --git a/lib/resize.js b/lib/resize.js index 66cfd871..665e0c87 100644 --- a/lib/resize.js +++ b/lib/resize.js @@ -150,6 +150,8 @@ function isResizeExpected (options) { * - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf). * - `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). + * - `mks2013`: Use a [Magic Kernel Sharp](https://johncostella.com/magic/mks.pdf) 2013 kernel, as adopted by Facebook. + * - `mks2021`: Use a Magic Kernel Sharp 2021 kernel, with more accurate (reduced) sharpening than the 2013 version. * * When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators. * Downsampling kernels without a matching upsampling interpolator map to `cubic`. diff --git a/test/types/sharp.test-d.ts b/test/types/sharp.test-d.ts index 88e5b45b..be8ce88d 100644 --- a/test/types/sharp.test-d.ts +++ b/test/types/sharp.test-d.ts @@ -188,6 +188,8 @@ sharp(input) // of the image data in inputBuffer }); +sharp(input).resize({ kernel: 'mks2013' }); + transformer = sharp() .resize(200, 200, { fit: 'cover',