showing results for - "canvas todataurl returns undefined"
Josué
22 Aug 2019
1//use callbacks instead of return, ex.
2function getImageDataURL(local_name, w, h, i, callback) {    
3    var data, canvas, ctx;
4    var img = new Image();
5  	img.src = "https://wallpapercave.com/wp/wp5042624.png";
6    img.onload = function (){      
7        canvas = document.createElement('canvas');
8        canvas.width = w;
9        canvas.height = h;
10        ctx = canvas.getContext("2d");
11        ctx.drawImage(img,0,0,w,h);
12
13        callback(canvas.toDataURL("image/png"));
14    }
15}
16
17getImageDataURL('image', 100, 100, 'image.png', function (data) {
18    console.log(data);
19});