You can use the lowering step to achieve better results. Most browsers seem to use linear interpolation rather than bicubic when resizing images.
( Update The imageSmoothingQuality quality imageSmoothingQuality which is currently only available in Chrome, has been added to the specification.)
If the smoothing mode or the nearest neighbor is not selected, the browser will always interpolate the image after it is reduced, since this function is used as a low-pass filter to avoid overlapping.
The bilinear uses 2x2 pixels for interpolation, while the bi-cubic uses 4x4, so by doing this in stages, you can get closer to the bi-cubic result using bilinear interpolation, as seen in the images.
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var img = new Image(); img.onload = function () {
<img src="//i.imgur.com/SHo6Fub.jpg" width="300" height="234"> <canvas id="canvas" width=300></canvas>
Depending on how sharp your size is, you can skip step 2 if the difference is smaller.
In the demo, you can see that the new result is now very similar to the image element.
user1693593 09 Oct '13 at 3:08 on 2013-10-09 03:08
source share