2023-08-21 10:55:39 +08:00
|
|
|
import html2canvas from "html2canvas";
|
|
|
|
|
const getJpeg = dom =>{
|
|
|
|
|
return new Promise(resolve =>{
|
|
|
|
|
html2canvas(dom,{useCORS: true,}).then(canvas =>{
|
|
|
|
|
const jpeg = canvas.toDataURL('image/jpeg',1.0);
|
|
|
|
|
resolve(base64ToFile(jpeg))
|
2023-08-23 17:50:09 +08:00
|
|
|
console.log(jpeg,'=========');
|
2023-08-21 10:55:39 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const base64ToFile = urlData =>{
|
|
|
|
|
const arr = urlData.split(',');
|
|
|
|
|
const mime = arr[0].match(/:(.*?);/)[1]
|
|
|
|
|
const bytes = atob(arr[1])
|
|
|
|
|
let n = bytes.length;
|
|
|
|
|
const ia = new Uint8Array(n)
|
|
|
|
|
while (n--){
|
|
|
|
|
ia[n] = bytes.charCodeAt(n);
|
|
|
|
|
}
|
|
|
|
|
console.log(new File([ia],'jpeg',{type:mime}));
|
|
|
|
|
return new File([ia],'jpeg',{type:mime})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
export default getJpeg
|