dg-npm-templates
Version:
Npx generator for react app dependency creation by digite
22 lines (16 loc) • 622 B
JavaScript
/* istanbul ignore file */
const FileUtil = {
getBase64Image( imgEl ) {
/* NOTE:imgElem must be on the same server otherwise a cross-origin error
will be thrown "SECURITY_ERR: DOM Exception 18" */
const img = document.createElement('img');
img.src = imgEl.src;
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(imgEl, 0, 0);
return canvas.toDataURL('image/png');
}
}
export default FileUtil;