imageCompress(file){
return new Promise((resolve, reject)=>{
let { size,path } = file
let type = path.split(".")[1]
//大于0.5M进行压缩,
if(size< (0.5*1024*1024)){
resolve(file)
return false
}
uni.compressImage({
src: path,
quality: this.quality,
width: "60%",
height: "60%",
success: res => {
let newPath = res.tempFilePath
let newName = res.tempFilePath.split("/")[res.tempFilePath.split("/").length-1]
uni.getFileInfo({
filePath:res.tempFilePath,
success:async (info)=>{
let newFile = {...file,size:info.size,path:newPath,name:newName,tempFilePath:res.tempFilePath}
this.quality *=0.9;
resolve(await this.imageCompress(newFile))
}
})
}
})
})
}
标签:res,app,tempFilePath,let,file,path,uni,压缩,size
From: https://www.cnblogs.com/congshaoblog/p/18020401