Answers for "canvas todataurl returns undefined"

0

canvas todataurl returns undefined

//use callbacks instead of return, ex.
function getImageDataURL(local_name, w, h, i, callback) {    
    var data, canvas, ctx;
    var img = new Image();
  	img.src = "https://wallpapercave.com/wp/wp5042624.png";
    img.onload = function (){      
        canvas = document.createElement('canvas');
        canvas.width = w;
        canvas.height = h;
        ctx = canvas.getContext("2d");
        ctx.drawImage(img,0,0,w,h);

        callback(canvas.toDataURL("image/png"));
    }
}

getImageDataURL('image', 100, 100, 'image.png', function (data) {
    console.log(data);
});
Posted by: Guest on August-08-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language