'use strict';

/**
 * 图片转Base64字符串
 * @param {*} image
 * @returns
 */
function imageToBase64(image) {
  var canvas = document.createElement('canvas');
  canvas.width = image.width;
  canvas.height = image.height;
  var ctx = canvas.getContext('2d');
  ctx.drawImage(image, 0, 0, image.width, image.height);
  var ext = image.src.substring(image.src.lastIndexOf('.') + 1).toLowerCase();
  return canvas.toDataURL("images/".concat(ext));
}

module.exports = imageToBase64;
