function sliceSquare(srcCanvas) {
  const SQUARE_SIZE = srcCanvas.height / 3;
  let destCanvas = document.createElement("canvas");
  let destCtx = destCanvas.getContext("2d");

  /**
    * @desc appends image to DOM
    * @param row int - row number (0-2)
    * @param col int - col number (0-2)
  */
  function appendImage(row, col) {
    let img = new Image();

    destCtx.drawImage(
      srcCanvas,
      SQUARE_SIZE * row,
      SQUARE_SIZE * col,
      SQUARE_SIZE,
      SQUARE_SIZE,
      0,
      0,
      destCanvas.width,
      destCanvas.height
    )

    img.className = "square";
    // img.src = destCanvas.toDataURL("image/png");
    img.src = destCanvas.toDataURL("image/jpeg");
    document.querySelector("#output").appendChild(img);
  }

  destCanvas.width = SQUARE_SIZE;
  destCanvas.height = SQUARE_SIZE;

  for (let col = 0; col < 3; col++) {
    for (let row = 0; row < 3; row++) {
      appendImage(row, col);
    }
  }

  return new Promise((resolve) => resolve());
}
/**
  * @desc Creates one square slice of a segment of the image and adds it to DOM
  * @param srcCanvas canvas - image object
  * @return promise - resolves with input image to allow chaining
*/
@desc Creates one square slice of a segment of the image and adds it to DOM
@param srcCanvas canvas - image object
@return promise - resolves with input image to allow chaining
@desc Creates one square slice of a segment of the image and adds it to DOM @param srcCanvas canvas - image object @return promise - resolves with input image to allow chaining
function sliceSquare(srcCanvas) {
  const SQUARE_SIZE = srcCanvas.height / 3;
  let destCanvas = document.createElement("canvas");
  let destCtx = destCanvas.getContext("2d");
  function appendImage(row, col) {
    let img = new Image();
    destCtx.drawImage(
      srcCanvas,
      SQUARE_SIZE * row,
      SQUARE_SIZE * col,
      SQUARE_SIZE,
      SQUARE_SIZE,
      0,
      0,
      destCanvas.width,
      destCanvas.height
    )
    img.className = "square";
    img.src = destCanvas.toDataURL("image/jpeg");
    document.querySelector("#output").appendChild(img);
  }
  destCanvas.width = SQUARE_SIZE;
  destCanvas.height = SQUARE_SIZE;
  for (let col = 0; col < 3; col++) {
    for (let row = 0; row < 3; row++) {
      appendImage(row, col);
    }
  }
  return new Promise((resolve) => resolve());
}
function sliceSquare ( srcCanvas ) { const SQUARE_SIZE = srcCanvas . height / 3 ; let destCanvas = document . createElement ( "canvas" ) ; let destCtx = destCanvas . getContext ( "2d" ) ; function appendImage ( row , col ) { let img = new Image ( ) ; destCtx . drawImage ( srcCanvas , SQUARE_SIZE * row , SQUARE_SIZE * col , SQUARE_SIZE , SQUARE_SIZE , 0 , 0 , destCanvas . width , destCanvas . height ) img . className = "square" ; img . src = destCanvas . toDataURL ( "image/jpeg" ) ; document . querySelector ( "#output" ) . appendChild ( img ) ; } destCanvas . width = SQUARE_SIZE ; destCanvas . height = SQUARE_SIZE ; for ( let col = 0 ; col < 3 ; col ++ ) { for ( let row = 0 ; row < 3 ; row ++ ) { appendImage ( row , col ) ; } } return new Promise ( ( resolve ) => resolve ( ) ) ; }
@desc Creates one square slice of a segment of the image and adds it to DOM
 @param srcCanvas canvas - image object
 @return promise - resolves with input image to allow chaining
@desc Creates one square slice of a segment of the image and adds it to DOM @param srcCanvas canvas - image object @return promise - resolves with input image to allow chaining
/**
    * @desc appends image to DOM
    * @param row int - row number (0-2)
    * @param col int - col number (0-2)
  */ // img.src = destCanvas.toDataURL("image/png");
