function(imgFile,quality = 0.7){
return new Promise((resolve,reject)=>{
const fileReader=new FileReader();
const imgObj=new Image();
const canvas=document.createElement(“canvas”);
const ctx = canvas.getContext(‘2d’);
fileReader.readAsDataURL(imgFile);
fileReader.οnlοad=(e)=>{
imgObj.src=e.target.result
const w = imgObj.width;
const h = imgObj.height;
ctx.drawImage(imgObj, 0, 0, w, h);//imgObj,x,y,w,h
var base64 = canvas.toDataURL(‘image/jpeg’, quality);
resolve(base64)
}
})
}
图片转base64上传
最新推荐文章于 2024-05-31 09:05:13 发布