let img = new Image();
img.src = '图片的链接';
img.onload = async () => {
console.log(img.width)
console.log(img.height)
};`
注意:一定要onload,要不是异步的,取不到值
封装:
async function getVideo(fileUrl: any) {
return new Promise((resolve) => {
let img = new Image();
img.src = fileUrl;
img.onload = async () => {
let type = img.width / img.height > 1 ? "video-w" : "video-h";
resolve(type);
};
});
}
调用:
getVideo(url).then((res) => {
console.log(res);
});