canvas load image code example
Example 1: js image on canvas
base_image = new Image();
base_image.src = 'img/base.png';
base_image.onload = () => ctx.drawImage(base_image, 0, 0);
Example 2: load images js context
function loadImage(url) {
return new Promise(r => { let i = new Image(); i.onload = (() => r(i)); i.src = url; });
}
let img = await loadImage("./my/image/path.jpg");
ctx.drawImage(img, 0, 0);