code: function (source, $destination, maxSize) {
              var size = calculateSize(source, maxSize);
              setDimensions($destination, size, 1);
              var destCtx = $destination[0].getContext('2d');
              destCtx.drawImage(source, 0, 0, source.width, source.height,
                  0, 0, size.width, size.height);
          }
docs: Draw an image (<img>) or contents of a canvas to another canvas. The destination
  canvas is resized properly.
  @param source The image or source canvas to draw on a new canvas.
  @param $destination The destination canvas to draw onto.
  @param maxSize Maximum width or height of the destination canvas.