Resizing an image in an HTML5 canvas

后端 未结 18 3025
半阙折子戏
半阙折子戏 2020-11-22 03:37

I\'m trying to create a thumbnail image on the client side using javascript and a canvas element, but when I shrink the image down, it looks terrible. It looks as if it was

18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 04:05

    Try pica - that's a highly optimized resizer with selectable algorythms. See demo.

    For example, original image from first post is resized in 120ms with Lanczos filter and 3px window or 60ms with Box filter and 0.5px window. For huge 17mb image 5000x3000px resize takes ~1s on desktop and 3s on mobile.

    All resize principles were described very well in this thread, and pica does not add rocket science. But it's optimized very well for modern JIT-s, and is ready to use out of box (via npm or bower). Also, it use webworkers when available to avoid interface freezes.

    I also plan to add unsharp mask support soon, because it's very useful after downscale.

提交回复
热议问题