function loadCanvas(img) {
  const SRC_MAX_SIZE = Math.max(img.naturalWidth, img.naturalHeight);
  const SRC_ASPECT = img.naturalWidth / img.naturalHeight;
  let canvas = document.createElement("canvas");
  let ctx = canvas.getContext("2d");
  let targetWidth = 0;
  let targetHeight = 0;

  if (SRC_ASPECT > 1) {
    targetWidth = Math.min(img.naturalWidth, 4500);
    targetHeight = targetWidth / SRC_ASPECT;
  } else {
    targetHeight = Math.min(img.naturalHeight, 4500);
    targetWidth = targetHeight * SRC_ASPECT;
  }

  canvas.width = Math.min(SRC_MAX_SIZE, 4500);
  canvas.height = canvas.width;

  ctx.fillStyle = document.getElementById("background").value;
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  
  ctx.drawImage(img,
    0,
    0,
    img.naturalWidth,
    img.naturalHeight,
    (canvas.width - targetWidth) / 2,   //offset for non square image
    (canvas.height - targetHeight) / 2, //offset for non square image
    targetWidth,
    targetHeight
  );
  return new Promise((resolve) => resolve(canvas));
}
/**
  * @desc loads image to square canvas
  * @param img image - image to be loaded
  * @return promise - resolves with canvas
*/
@desc loads image to square canvas
@param img image - image to be loaded
@return promise - resolves with canvas
@desc loads image to square canvas @param img image - image to be loaded @return promise - resolves with canvas
function loadCanvas(img) {
  const SRC_MAX_SIZE = Math.max(img.naturalWidth, img.naturalHeight);
  const SRC_ASPECT = img.naturalWidth / img.naturalHeight;
  let canvas = document.createElement("canvas");
  let ctx = canvas.getContext("2d");
  let targetWidth = 0;
  let targetHeight = 0;
  if (SRC_ASPECT > 1) {
    targetWidth = Math.min(img.naturalWidth, 4500);
    targetHeight = targetWidth / SRC_ASPECT;
  } else {
    targetHeight = Math.min(img.naturalHeight, 4500);
    targetWidth = targetHeight * SRC_ASPECT;
  }
  canvas.width = Math.min(SRC_MAX_SIZE, 4500);
  canvas.height = canvas.width;
  ctx.fillStyle = document.getElementById("background").value;
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  ctx.drawImage(img,
    0,
    0,
    img.naturalWidth,
    img.naturalHeight,
    (canvas.width - targetWidth) / 2,   
    (canvas.height - targetHeight) / 2, 
    targetWidth,
    targetHeight
  );
  return new Promise((resolve) => resolve(canvas));
}
function loadCanvas ( img ) { const SRC_MAX_SIZE = Math . max ( img . naturalWidth , img . naturalHeight ) ; const SRC_ASPECT = img . naturalWidth / img . naturalHeight ; let canvas = document . createElement ( "canvas" ) ; let ctx = canvas . getContext ( "2d" ) ; let targetWidth = 0 ; let targetHeight = 0 ; if ( SRC_ASPECT > 1 ) { targetWidth = Math . min ( img . naturalWidth , 4500 ) ; targetHeight = targetWidth / SRC_ASPECT ; } else { targetHeight = Math . min ( img . naturalHeight , 4500 ) ; targetWidth = targetHeight * SRC_ASPECT ; } canvas . width = Math . min ( SRC_MAX_SIZE , 4500 ) ; canvas . height = canvas . width ; ctx . fillStyle = document . getElementById ( "background" ) . value ; ctx . fillRect ( 0 , 0 , canvas . width , canvas . height ) ; ctx . drawImage ( img , 0 , 0 , img . naturalWidth , img . naturalHeight , ( canvas . width - targetWidth ) / 2 , ( canvas . height - targetHeight ) / 2 , targetWidth , targetHeight ) ; return new Promise ( ( resolve ) => resolve ( canvas ) ) ; }
@desc loads image to square canvas
 @param img image - image to be loaded
 @return promise - resolves with canvas
@desc loads image to square canvas @param img image - image to be loaded @return promise - resolves with canvas
//offset for non square image
 //offset for non square image
