code: function resize2Canvas(img, width, height) {
      if (!img) {
        throw new Error('`img` is required.');
      }
      // 计算新图片的宽高
      var newImageDimentions = getNewImageDimentions(img, width, height);
      width = newImageDimentions[0];
      height = newImageDimentions[1];
      
      // 画到 canvas 中
      var canvas = document.createElement('canvas');
      canvas.width = width;
      canvas.height = height;
      var ctx = canvas.getContext('2d');
      ctx.drawImage(img, 0, 0, width, height);
      return canvas;
    }
docs: resize an <img> or <canvas> to canvas
  @param  {Image}  img    an <img> or Image() or <canvas>
  @param  {number} width  output image width
  @param  {number} height output image height
  @return {Canvas}        output image canvas