我使用 2 个库(heic2any 和图像转换)来尝试将 heic 图像转换和压缩为 jpeg。目前,我无法获得按正确顺序返回的承诺
e = screenInput(e);
async function screenInput(filename) {
//checks file extension
var ext = getExtension(filename);
switch (ext.toLowerCase()) {
case 'jpg':
case 'jpeg':
case 'png':
case 'bmp':
return(compressim(filename));
break;
case 'heic':
var url = URL.createObjectURL(filename)
var result = await heicConvert(url)
return compressOnly(result);
break;
default:
return filename
break;
}
}
function heicConvert(input) {
return fetch(input)
.then((res)=>res.blob())
.then((blob)=>(heic2any({blob,toType:"image/jpeg"})))
}
function compressOnly(image) {
var file
file = new File([imageConversion.compressAccurately(image,500)], image.name, {type: "image/jpeg"})
return file
}
目前它返回一个未决的承诺
var result = await heicConvert(url)
甚至在开始 compressOnly(result);
任何帮助将不胜感激,已经坚持了一段时间!