code: function resizeImage(ctx, imageData, width, height) {
    const {naturalWidth, naturalHeight} = imageData;
    if (width === naturalWidth && height === naturalHeight) {
      return imageData;
    }
  
    ctx.canvas.height = height;
    ctx.canvas.width = width;
  
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  
    // image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight
    ctx.drawImage(imageData, 0, 0, naturalWidth, naturalHeight, 0, 0, width, height);
  
    return ctx.canvas;
  }
docs: resize image to given width and height