src/utils/convert.js
/**
* Rendering image element (with resizing) into the canvas element
*/
Rendering image element (with resizing) into the canvas element
Rendering image element ( with resizing ) into the canvas element
function renderImageToCanvas(img, canvas, options, doSquash) {
  var iw = img.naturalWidth, ih = img.naturalHeight;
  var width = options.width, height = options.height;
  var ctx = canvas.getContext('2d');
  ctx.save();
  transformCoordinate(canvas, ctx, width, height, options.orientation);
  var subsampled = detectSubsampling(img);
  if (subsampled) {
    iw /= 2;
    ih /= 2;
  }
  var d = 1024; 
  var tmpCanvas = document.createElement('canvas');
  tmpCanvas.width = tmpCanvas.height = d;
  var tmpCtx = tmpCanvas.getContext('2d');
  var vertSquashRatio = doSquash ? detectVerticalSquash(img, iw, ih) : 1;
  var dw = Math.ceil(d * width / iw);
  var dh = Math.ceil(d * height / ih / vertSquashRatio);
  var sy = 0;
  var dy = 0;
  while (sy < ih) {
    var sx = 0;
    var dx = 0;
    while (sx < iw) {
      tmpCtx.clearRect(0, 0, d, d);
      tmpCtx.drawImage(img, -sx, -sy);
      ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);
      sx += d;
      dx += dw;
    }
    sy += d;
    dy += dh;
  }
  ctx.restore();
  tmpCanvas = tmpCtx = null;
}
function renderImageToCanvas ( img , canvas , options , doSquash ) { var iw = img . naturalWidth , ih = img . naturalHeight ; var width = options . width , height = options . height ; var ctx = canvas . getContext ( '2d' ) ; ctx . save ( ) ; transformCoordinate ( canvas , ctx , width , height , options . orientation ) ; var subsampled = detectSubsampling ( img ) ; if ( subsampled ) { iw /= 2 ; ih /= 2 ; } var d = 1024 ; var tmpCanvas = document . createElement ( 'canvas' ) ; tmpCanvas . width = tmpCanvas . height = d ; var tmpCtx = tmpCanvas . getContext ( '2d' ) ; var vertSquashRatio = doSquash ? detectVerticalSquash ( img , iw , ih ) : 1 ; var dw = Math . ceil ( d * width / iw ) ; var dh = Math . ceil ( d * height / ih / vertSquashRatio ) ; var sy = 0 ; var dy = 0 ; while ( sy < ih ) { var sx = 0 ; var dx = 0 ; while ( sx < iw ) { tmpCtx . clearRect ( 0 , 0 , d , d ) ; tmpCtx . drawImage ( img , - sx , - sy ) ; ctx . drawImage ( tmpCanvas , 0 , 0 , d , d , dx , dy , dw , dh ) ; sx += d ; dx += dw ; } sy += d ; dy += dh ; } ctx . restore ( ) ; tmpCanvas = tmpCtx = null ; }
Rendering image element (with resizing) into the canvas element
Rendering image element ( with resizing ) into the canvas element
// size of tiling canvas