function drawScaledImage(img) {
  let canvas = document.createElement("canvas");
  let context = canvas.getContext("2d");
  [canvas.width, canvas.height] = [1920, 1080];
  let hRatio = canvas.width/img.width;
  let vRatio = canvas.height/img.height;
  let ratio = Math.max(hRatio, vRatio);
  let centerShift_x = (canvas.width - img.width * ratio) / 2;
  let centerShift_y = (canvas.height - img.height * ratio) / 2;
  context.drawImage(img, 0, 0, img.width, img.height, centerShift_x, centerShift_y, img.width * ratio, img.height * ratio);
  return canvas;
}
/**
 * Draws and rescales the given image in a canvas and returns it
 * @function drawScaledImage
 * @param {HTMLImageElement} img Image element to rescale
 * @returns {HTMLCanvasElement} Canvas containing the rescaled image
 */
Draws and rescales the given image in a canvas and returns it
@function drawScaledImage
@param {HTMLImageElement} img Image element to rescale
@returns {HTMLCanvasElement} Canvas containing the rescaled image
Draws and rescales the given image in a canvas and returns it @function drawScaledImage @param { HTMLImageElement } img Image element to rescale @returns { HTMLCanvasElement } Canvas containing the rescaled image
function drawScaledImage(img) {
  let canvas = document.createElement("canvas");
  let context = canvas.getContext("2d");
  [canvas.width, canvas.height] = [1920, 1080];
  let hRatio = canvas.width/img.width;
  let vRatio = canvas.height/img.height;
  let ratio = Math.max(hRatio, vRatio);
  let centerShift_x = (canvas.width - img.width * ratio) / 2;
  let centerShift_y = (canvas.height - img.height * ratio) / 2;
  context.drawImage(img, 0, 0, img.width, img.height, centerShift_x, centerShift_y, img.width * ratio, img.height * ratio);
  return canvas;
}
function drawScaledImage ( img ) { let canvas = document . createElement ( "canvas" ) ; let context = canvas . getContext ( "2d" ) ; [ canvas . width , canvas . height ] = [ 1920 , 1080 ] ; let hRatio = canvas . width / img . width ; let vRatio = canvas . height / img . height ; let ratio = Math . max ( hRatio , vRatio ) ; let centerShift_x = ( canvas . width - img . width * ratio ) / 2 ; let centerShift_y = ( canvas . height - img . height * ratio ) / 2 ; context . drawImage ( img , 0 , 0 , img . width , img . height , centerShift_x , centerShift_y , img . width * ratio , img . height * ratio ) ; return canvas ; }
Draws and rescales the given image in a canvas and returns it
 @function drawScaledImage
 @param {HTMLImageElement} img Image element to rescale
 @returns {HTMLCanvasElement} Canvas containing the rescaled image
Draws and rescales the given image in a canvas and returns it @function drawScaledImage @param { HTMLImageElement } img Image element to rescale @returns { HTMLCanvasElement } Canvas containing the rescaled image