Search code examples
javascriptimage-processinghtml5-canvasblobjpeg

How to maintain image size when converting canvas to blob


When I do the following:

canvas.toBlob(blob=>{

}, 'image/jpeg', 1);

Somehow the blob is downgraded to 300px*150px. How can I maintain the original size of the canvas image?


Solution

  • I got it!

    By default, the width and height of canvas are 300px and 150px respectively.

    I need to do the following:

    <canvas width="640" height="480"></canvas>
    

    Setting the dimensions with CSS won't do.