This commit is contained in:
X1627315083
2025-09-01 14:03:30 +08:00
parent c387a71ba8
commit 89639aaec9
49 changed files with 819 additions and 232 deletions

View File

@@ -2,13 +2,14 @@ import html2canvas from "html2canvas";
const getJpeg = dom =>{
return new Promise(resolve =>{
setTimeout(() => {
html2canvas(dom,{useCORS: true,}).then(canvas =>{
let base64 = canvas.toDataURL('image/jpeg',.9);
html2canvas(dom,{useCORS: true,backgroundColor: null}).then(canvas =>{
let base64 = canvas.toDataURL('image/png',.9);
console.log(base64)
// let quality = 0.9 // 压缩系数0-1之间
let newImage = new Image()
newImage.src = base64
newImage.setAttribute('crossOrigin', 'Anonymous') // url为外域时需要
const filename = new Date().toISOString() + '.jpg';
const filename = new Date().toISOString() + '.png';
resolve(base64ToFile(base64,filename))
newImage.remove()
// }
@@ -29,7 +30,7 @@ function base64ToFile(base64,filename) {
const byteArray = new Uint8Array(byteNumbers);
// 创建 File 对象
const file = new File([byteArray], filename, { type: 'image/jpeg' }); // 根据需要的类型进行修改
const file = new File([byteArray], filename, { type: 'image/png' }); // 根据需要的类型进行修改
return file;
}
//base64转成blob
@@ -39,7 +40,7 @@ function dataURLtoFile(dataURI, type) {
for (let i = 0; i < binary.length; i++) {
array.push(binary.charCodeAt(i));
}
return new Blob([new Uint8Array(array)], { type: "image/jpeg" });
return new Blob([new Uint8Array(array)], { type: "image/png" });
}
//转换