How can I update the width and heigth of a cava actuamaticamente. What happens is that I have an image to which I resize it, to larger or smaller size and the canvas takes me the original measurement and not the new one that I added to the image through a css class, I tried to copy the measurements of the class and give them to the canvas but this does not work for me, any solution?
function canvas(resize, newWidth, newHeight ) {
var Width = $('.renders').css("width");
var Height = $('.renders').css("height");
var img= document.getElementById('true');
img.addEventListener('mousemove', function (e) {
let ctx;
if(!this.canvas) {
this.canvas = document.createElement('canvas');
this.canvas.width = this.width ;
this.canvas.height = this.height;
ctx=this.canvas.getContext('2d');
ctx.drawImage(this, 0, 0, this.width, this.height);
} else {
ctx=this.canvas.getContext('2d');
}
const pixel = ctx.getImageData(e.offsetX, e.offsetY, 1, 1).data;
detectar_color(ctx,e,img);
});
}