canvas draw 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: crop image canvas
var image = new Image(),
canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d');
image.src = 'https://i.stack.imgur.com/I4jXc.png';
image.onload = function(){
ctx.drawImage(image,
70, 20,
50, 50,
0, 0,
100, 100);
}
Example 3: js canvas draw image
ctx.drawImage(image, x, y)
ctx.drawImage(image, x, y, width, height)