ice.fo.utils
Version:
40 lines (35 loc) • 826 B
JavaScript
import html2canvas from 'html2canvas'
/**
*
* @param {*} el
* @param {*} mode base64|blob
* @returns
*/
export default async function captureElementScreenshot (el, options = {}) {
options = Object.assign({
mode: 'base64',
windowWidth: 1366,
imageWidth: options.windowWidth || 1366,
imageHeight: 768,
}, options)
if (!el) {
el = document.body
}
const canvas = await html2canvas(el, {
backgroundColor: null,
windowWidth: options.windowWidth,
width: options.imageWidth,
height: options.imageHeight,
scale: 1,
allowTaint: true,
useCORS: true,
// removeContainer: false,
})
switch (options.mode) {
case 'blob':
return new Promise(resolve => canvas.toBlob(resolve))
case 'base64':
default:
return canvas.toDataURL('image/png')
}
}