// 从指定的url地址获取图像尺寸信息
function getImageSizeByUrl2(url, index, callback) {
let image = new Image();
image.onload = function () {
callback(index, {
width: image.width,
height: image.height
});
};
image.onerror = function () {
callback(index, {
width: 0,
height: 0
});
};
image.src = url;
}
//加载试卷图片尺寸
function loadPaperSize2(startIndex, getLen, callback) {
pagePaperImageSize = [];
for (var ix = 0; ix < pageArrPapers.length; ix++) {
pagePaperImageSize.push({
width: 0,
height: 0
});
}
for (var ix = 0; ix < pageArrPapers.length; ix++) {
var imageUrl = (pageEditState ? "" : formHost) + pageArrPapers[ix]; // 获取图像url地址
getImageSizeByUrl2(imageUrl, ix, function (index, param) {
pagePaperImageSize[index] = param;
if (index == pageArrPapers.length - 1) {
callback();
}
});
}
}
从指定的url地址获取图像尺寸信息
最新推荐文章于 2024-07-15 14:55:00 发布
文章介绍了两个JavaScript函数:getImageSizeByUrl2用于从给定URL获取图像尺寸信息,loadPaperSize2则遍历试卷图片数组,通过getImageSizeByUrl2异步加载每个图片的尺寸,并在所有尺寸加载完成后调用回调。
摘要由CSDN通过智能技术生成