What is resampling (interpolation)?
Resampling is the process of calculating new pixel values when an image is resized or transformed, using an interpolation method such as nearest-neighbor, bilinear, bicubic or Lanczos.
By Rocco Bombardieri · Updated
Explained in more detail
Whenever you change an image's pixel dimensions, the new pixels do not line up with the old ones. Resampling estimates each new pixel's color from nearby original pixels. The estimating rule is the interpolation method.
Nearest-neighbor copies the closest original pixel. It is fast and keeps hard edges, so it suits pixel art, but it looks blocky when enlarging and jagged when shrinking. Bilinear averages the four nearest pixels, giving smooth but slightly soft results. Bicubic uses a larger neighbourhood and produces sharper results. Lanczos uses an even wider window and is often preferred for downscaling photographs, with a risk of ringing near high-contrast edges.
When shrinking, quality depends on averaging all the source pixels that map to each output pixel. Methods that sample only a few neighbours can skip detail and create aliasing, such as moiré patterns or shimmering lines. Reducing in several moderate steps rather than one very large step can help in some implementations.
In browsers, canvas drawImage scales with smoothing controlled by imageSmoothingEnabled and imageSmoothingQuality, which takes the values "low" (the default), "medium" or "high". MDN does not say which algorithm each level uses, so assume it can differ between browsers. Triim's resize and square tools turn smoothing on and request the high-quality setting.
Resampling can never add real detail. Enlarging an image only invents plausible in-between pixels, which is why upscaled images look soft.