//按缩略比重新计算图片显示大小
function ReSizeImage(ImgObj, maxWidth, maxHeight) {
var image = new Image();
image.onload = function () {
// console.log('width:' + image.width + ',height:' + image.height);
var tempWidth;
var tempHeight;
if (image.width > 0 && image.height > 0) {
if (image.width / image.height >= maxWidth / maxHeight) {
if (image.width > maxWidth) {
tempWidth = maxWidth;
tempHeight = (image.height * maxWidth) / image.width;
}
else {
tempWidth = image.width;
tempHeight = image.height;
}
} else {
if (image.height > maxHeight) {
tempHeight = maxHeight;
tempWidth = (image.width * maxHeight) / image.height;
} else {
tempWidth = image.width;
tempHeight = image.height;
}
}
ImgObj.height = tempHeight;
ImgObj.width = tempWidth;
}
}
image.src = ImgObj.src;
}