DEV Community

Cover image for sharp resize kernels compared: lanczos3, mitchell, nearest by PSNR
Sahadat Husain
Sahadat Husain

Posted on

sharp resize kernels compared: lanczos3, mitchell, nearest by PSNR

Keep sharp's default, lanczos3. When we shrank a 1920 × 1076 photo to a quarter of its size, lanczos3 kept the most detail (33.02 dB PSNR) and linear kept the least of the smooth kernels (32.29 dB). The price is bytes: the lanczos3 JPEG was 20.5 KB and the linear one 19.0 KB, 7.8% less. Resize speed barely differed, at a few milliseconds each.

Below are the eight kernels, the test, and the one result that looks wrong: nearest scoring highest at half size.

What are the resize kernels in sharp?

The kernel option in resize() picks the filter used when an image shrinks. The sharp docs list eight: nearest, linear (a triangle filter), cubic (Catmull-Rom), mitchell, lanczos2, lanczos3 (the default), mks2013 and mks2021 (Magic Kernel Sharp). Sharper filters keep fine detail but can ring around hard edges. Softer filters blur a little and compress better.

How do you score a resize kernel?

A resized image has no ground truth to compare against. So I used a round trip. Shrink with the kernel, enlarge back to the original size with lanczos3, and compute PSNR against the original pixels. A higher score means the small image kept more of what the big one had.

import sharp from 'sharp';

const { data, info } = await sharp(src).rotate().resize({ width: 1920 })
  .removeAlpha().raw().toBuffer({ resolveWithObject: true });
const raw = { raw: { width: info.width, height: info.height, channels: 3 } };

for (const kernel of ['nearest', 'linear', 'cubic', 'mitchell',
                      'lanczos2', 'lanczos3', 'mks2013', 'mks2021']) {
  const w = Math.round(info.width / 4), h = Math.round(info.height / 4);
  const small = await sharp(data, raw).resize(w, h, { kernel }).raw().toBuffer();
  const back = await sharp(small, { raw: { width: w, height: h, channels: 3 } })
    .resize(info.width, info.height, { kernel: 'lanczos3' }).raw().toBuffer();
  let sum = 0;
  for (let i = 0; i < back.length; i++) sum += (back[i] - data[i]) ** 2;
  const psnr = 10 * Math.log10(65025 / (sum / back.length));
  const jpeg = await sharp(small, { raw: { width: w, height: h, channels: 3 } })
    .jpeg({ quality: 80 }).toBuffer();
  console.log(kernel, psnr.toFixed(2), 'dB', (jpeg.length / 1000).toFixed(1), 'KB');
}
Enter fullscreen mode Exit fullscreen mode

The photo is our 4964 × 2782 camera photo (a lake at sunset), resized to 1920 × 1076 first. This is what the 1/4 run printed for the 480 × 269 result:

nearest   32.31 dB   22.3 KB
linear    32.29 dB   19.0 KB
cubic     32.87 dB   20.1 KB
mitchell  32.53 dB   19.3 KB
lanczos2  32.88 dB   20.1 KB
lanczos3  33.02 dB   20.5 KB
mks2013   33.01 dB   21.2 KB
mks2021   32.98 dB   20.4 KB
Enter fullscreen mode Exit fullscreen mode

Bars of resize kernel PSNR and output bytes for a photo and a screenshot shrunk to a quarter of their size

Which kernel keeps the most detail?

On the photo at 1/4 size, three kernels sit within 0.04 dB of each other at the top: lanczos3 (33.02), mks2013 (33.01) and mks2021 (32.98). Treat them as tied. Below them come lanczos2 and cubic at 32.88 and 32.87 dB, then mitchell at 32.53 and linear at 32.29.

The spread from best to worst is 0.73 dB. Mitchell is the interesting middle. It is 19.3 KB against 20.5 KB for lanczos3, a 5.5% saving for 0.49 dB less.

Why did nearest win at half size?

At 1/2 size (960 × 538) the photo results flip:

nearest   37.29 dB   64.3 KB
linear    34.96 dB   56.8 KB
cubic     35.27 dB   59.9 KB
mitchell  35.10 dB   57.8 KB
lanczos2  35.28 dB   60.0 KB
lanczos3  35.32 dB   61.2 KB
mks2013   35.17 dB   63.4 KB
mks2021   35.32 dB   60.8 KB
Enter fullscreen mode Exit fullscreen mode

Nearest scored 37.29 dB, 1.97 dB above lanczos3. I do not trust that as quality. At an exact 2:1 ratio, nearest keeps every other pixel untouched, and PSNR rewards exact copies. It does not penalise the jagged edges and shimmer that nearest adds on diagonal lines. At 1/4 size, where it can no longer do that, nearest scored 32.31 dB and fell to the bottom.

Nearest also wrote the biggest JPEG at both sizes (64.3 KB and 22.3 KB), probably because its hard pixel steps are costly to encode. I did not test that.

Note: Do not pick a kernel from PSNR alone. PSNR measures pixel error, not what a person sees. If one number surprises you, as nearest did, look at the picture.

What about screenshots with text?

I ran the same test on our pricing page screenshot, 1440 × 900, saving PNG output (so bytes track edge detail). At 1/4 size (360 × 225):

nearest   22.19 dB   31.4 KB
linear    23.12 dB   34.8 KB
cubic     23.48 dB   38.4 KB
mitchell  23.25 dB   40.6 KB
lanczos2  23.49 dB   38.3 KB
lanczos3  23.57 dB   42.1 KB
mks2013   23.62 dB   39.4 KB
mks2021   23.56 dB   40.0 KB
Enter fullscreen mode Exit fullscreen mode

Here mks2013 edged out lanczos3 on both scores: 23.62 dB at 39.4 KB against 23.57 dB at 42.1 KB. That is 6.3% fewer bytes and a slightly higher score. It is one screenshot, so I would read it as a hint, not a rule. Nearest again wins at half size (27.43 dB against 25.91 dB for lanczos3) and loses at a quarter.

How long does each kernel take?

Each resize ran 5 times and I kept the median. On the 1920 × 1076 photo, the 1/2 shrink took between 3.3 ms (nearest) and 8.3 ms (mks2013). Lanczos3 took 7.9 ms and linear 4.1 ms. At 1/4 size every kernel took between 4.2 ms and 8.5 ms, apart from lanczos2 with a 22.8 ms median I cannot explain and did not repeat.

At these sizes the kernel is not a performance decision. Pick it for the picture.

Which kernel should you use?

  • Photos for the web: leave lanczos3. It scored top or tied for top at both shrink ratios.
  • Photos where bytes matter more than the last 0.5 dB: try mitchell, which was 5.5% smaller at 1/4 size.
  • UI screenshots and text: test mks2013 against lanczos3 on your own images.
  • Pixel art that must stay crisp: nearest, at integer ratios only.

Our resize guide also scores sharp's kernels on this camera photo. It uses a different test, so its ranking of the smooth kernels differs from mine; read both before you change a default.

How I measured

  • Photo: apps/web/public/images/index/image-compressor-sample-camera-photo.jpeg, 4964 × 2782, resized to 1920 × 1076 as the reference.
  • Screenshot: apps/web/assets/reference/screenshot.png (our pricing page), resized to 1440 × 900 as the reference.
  • Versions: Node 24.22.0, sharp 0.35.4, libvips 8.18.6.
  • Score: shrink with each kernel, enlarge back with lanczos3, PSNR over RGB against the reference. Size: JPEG quality 80 for the photo, default PNG for the screenshot.
  • Time: resize only, from raw pixels, median of 5 runs. PSNR and bytes: one run per cell.
  • Machine: Apple M1 Pro, macOS, 2026-10-18. Harness: apps/web/scripts/devto-images/_measure-sharp-tuning.mjs; the blocks above are its measured.json, reformatted.

What I did not test

I did not run SSIM or any perceptual metric, view the outputs side by side, test enlarging with a kernel, or use fastShrinkOnLoad on JPEG input. Ratios other than 1/2 and 1/4 and a second photo are untested.


I build Blinkimg, an image compressor and converter with a developer API. I wrote this article with help from an AI assistant (Claude), which ran the code on my machine; every number in it comes from those runs.

Top comments (0)