Resizing an image in an HTML5 canvas

后端 未结 18 2734
半阙折子戏
半阙折子戏 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 03:54

    Fast and simple Javascript image resizer:

    https://github.com/calvintwr/blitz-hermite-resize

    const blitz = Blitz.create()
    
    /* Promise */
    blitz({
        source: DOM Image/DOM Canvas/jQuery/DataURL/File,
        width: 400,
        height: 600
    }).then(output => {
        // handle output
    })catch(error => {
        // handle error
    })
    
    /* Await */
    let resized = await blizt({...})
    
    /* Old school callback */
    const blitz = Blitz.create('callback')
    blitz({...}, function(output) {
        // run your callback.
    })
    

    History

    This is really after many rounds of research, reading and trying.

    The resizer algorithm uses @ViliusL's Hermite script (Hermite resizer is really the fastest and gives reasonably good output). Extended with features you need.

    Forks 1 worker to do the resizing so that it doesn't freeze your browser when resizing, unlike all other JS resizers out there.

提交回复
热议问题