How to update canvas width and height when resizing image


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.drawImage(this, 0, 0, this.width, this.height);
} else {
const pixel = ctx.getImageData(e.offsetX, e.offsetY, 1, 1).data;



asked by Jcastillovnz 09.11.2018 в 20:48

0 answers