Enlarge image to toDataURL - html2canvas

Before you tell me that this is a duplicate question, know that I looked through one each one related question and none of the answers in any of them work me.

I use html2canvas to get a snapshot of a div, and I need to scale to 750x1050 before saving it to png via canvas.toDataURL().

Closest I got the following code.

html2canvas(document.getElementById('div_id'), {
   onrendered: function(canvas) {

      var extra_canvas = document.createElement("canvas");

        extra_canvas.setAttribute('width', 750);
        extra_canvas.setAttribute('height', 1050);

        var ctx = extra_canvas.getContext('2d');
        ctx.drawImage(canvas, 0, 0, 750, 1050);
        var dataURL = extra_canvas.toDataURL();

        window.open(dataURL);
   }
});

The image was set up correctly, but the text inside the image was extremely low, as if it had resized after turning into png.

Is it that I am doing something wrong, or you simply cannot scale in this way?

/!

+6
3
+3

, ,

html2canvas($('#div_id'), {width: 750, height: 1050}).then(
    function(canvas) {
       window.open(canvas.toDataURL("image/png"));
    }
)

( ), , 110%, , window.devicePixelRatio 1.1000... , ( , ), , , fooobar.com/questions/707940/...

+2

, , . post. .

html2canvas(document.getElementById('div_id'), {
onrendered: function(canvas) {
        var ctx = canvas.getContext('2d');
        ctx.webkitImageSmoothingEnabled = false;
        ctx.mozImageSmoothingEnabled = false;
        ctx.imageSmoothingEnabled = false;
        var myImage = canvas.toDataURL("image/jpeg,1.0");  
       }
 }); 
0
source

All Articles