Your browser's canvas has exactly one resampling kernel, and it is bilinear. Not bicubic, not Lanczos, and — this is the part that surprised me — the imageSmoothingQuality setting changes nothing at all.
I measured it with an impulse response instead of trusting the documentation. The MDN page describes 'low', 'medium' and 'high' as different quality levels, which strongly implies different filters. In Chrome 157 on Linux, all three produce byte-identical output.
How I identified the kernel
A single white pixel on a 32x32 black canvas, drawn to 128x128 with smoothing on. The resulting row through the impulse centre:
0, 0, 0, 0, 0, 27, 83, 139, 195, 195, 139, 83, 27, 0, 0, 0, 0, 0
A symmetric ramp of eight non-zero taps, flat across the middle two. That is a triangle kernel — bilinear — sampled at 4x. Total energy came to 15.81 out of an expected 16, the 1.2% shortfall being 8-bit rounding at each tap. At 2x it is four taps, 47, 143, 143, 47; at 8x, sixteen taps stepping by exactly 30. Bilinear at every factor.
The 'low' and 'medium' settings return the same array, digit for digit. So the quality knob is not a filter selector in this engine — it appears to be a hint that only matters for the downscale path, and even there I could not make it fire (more on that below).
The bigger finding: two-pass is worse, and not by a little
If you upscale in two steps — 128 to 256, then 256 to 512 — you are not doing the same operation as a single draw. You are running bilinear twice, which is a triangle convolved with a triangle: a quadratic B-spline. It is smoother, blurrier, and measurably further from the truth.
| Path to 512x512 | PSNR vs ground truth | Δ vs direct |
|---|---|---|
| Direct single draw | 29.21 dB | — |
| 128→160→512 (1.25x) | 28.62 dB | −0.59 |
| 128→192→512 (1.50x) | 28.83 dB | −0.38 |
| 128→224→512 (1.75x) | 28.90 dB | −0.31 |
| 128→256→512 (2.00x) | 28.90 dB | −0.31 |
| 128→288→512 (2.25x) | 29.10 dB | −0.11 |
| 128→320→512 (2.50x) | 29.11 dB | −0.10 |
| 128→384→512 (3.00x) | 29.23 dB | +0.02 |
| 128→448→512 (3.50x) | 29.11 dB | −0.10 |
| 128→1024→512 (8.00x) | 29.20 dB | −0.01 |
Ground truth here is a 512x512 crop from a real 1080x1620 still shipped with the upscaler; the 128px input is an exact 4x4 block average of it, so nothing is invented on either side.
Read the table in two halves. Below 3x, two-pass costs up to 0.59 dB — real, repeatable, and in the direction you would predict from double-filtering. At 3x and above the deltas collapse to ±0.10 dB, which is the noise floor of this sweep: the 384px row at +0.02 and the 448px row at −0.10 bracket zero from either side.
The practical rule: if you must chain canvas draws, make the intermediate at least 3x the final size, or don't chain at all. The 1.25x row is the worst in the table and the 2x-then-2x row is the one you will actually hit, because "upscale twice for more detail" is a thing people write loops to do.
Controls, because a table like that is easy to fake
Three controls ran in the same page, same session:
- Idempotence — drawing a 512 canvas onto another 512 canvas returns a bit-identical image. Two draws at the same size change nothing.
- Identity — drawing 128 onto 128 returns the source exactly, max difference 0.
- Flat grey — a 128 grey field stays exactly 128 at the centre through both the single-pass and the two-pass arm. No drift, no gamma shift introduced by the chaining itself.
If any of those had failed, the two-pass deltas above would be measuring my harness rather than the engine.
It filters in sRGB, not linear light
This is the one that matters most for photo work and is almost never stated. A 2x2 source of three black pixels and one white, downscaled to a single pixel, returns 63. Averaging in linear light would give 188. The browser is averaging the encoded values, which means it is doing the arithmetic in the wrong space — technically, but consistently and by design, because that is what every 8-bit graphics pipeline has done since the 1990s.
I converted a real photo to linear light, upscaled it, converted back, and scored it: 28.80 dB against ground truth versus 29.21 dB for the browser's native sRGB-domain path. So on this image, "correct" linear-light filtering was 0.41 dB worse — and it differs from the native result on 33.9% of pixels by more than 2 code values.
That is not a bug in linear light. It is that ground truth was itself produced by a resampler working in sRGB, so the sRGB-domain path is being scored against its own bias. Both numbers are honest; neither is a universal winner. If you want to know which is right for your pipeline, the target has to be defined by the thing you are comparing to. I wrote up the general problem of picking the space separately in the gamma and linear-light notes.
What this means if you upscale in a browser
- Do not assume the browser gives you Lanczos. For a 4x upscale of a real photo, the canvas result sat 50.46 dB from PIL's bilinear and only 39.26 dB from PIL's Lanczos. It is bilinear, within one code value.
- Bilinear costs about 1 dB against Lanczos here. 29.21 vs 30.21 dB on the same input. If that gap matters to you, the fix is not a canvas setting — it is a WebGL shader or WASM resampler where you choose the kernel.
- Never chain small steps. One draw, or an intermediate at 3x or more.
- Tiling a large image into canvas draws introduces seams for exactly the reason above: each tile gets its own bilinear edge treatment. The measurement of how wide those seams get is in the tiled-upscale notes.
-
createImageBitmapwithresizeQuality: 'high'is not the same path. It landed 18 code values away from the canvas result and scored 49.68 dB against PIL bilinear — a slightly different filter, not a better one.
The whole measurement is a few dozen lines of JavaScript and PIL. If you want to check it on your own machine, the browser tool runs the same canvas path, and the impulse test takes about ten seconds to reproduce.
The short version
One kernel, three names that do nothing, and a two-pass chain that quietly costs you half a dB in the range where people actually use it. None of that is visible in a screenshot, which is why it survives in production for years.
Top comments (0)