画像サイズは、画像の形状に基づいて算出されます

/*计算图片尺寸*/
function caculateImgSize(url) {
	//限制最大尺寸
	let max_width = 690;
	let max_height = 600;
	let results;
	return new Promise((resolve, reject)=>{
		uni.getImageInfo({
			src: url,
			success: function(res) {
				//图片实际尺寸
				let width = res.width;
				let height = res.height;
				let rate = width / height;
				if (width > height) {
					//横图
					if (width <= max_width) {
						//无需限制宽度
						results = {
							"width": width,
							"height": height
						};
					} else {
						//限制宽度
						results = {
							"width": width,
							"height": width / rate
						};
					}
				} else {
					//竖图
					if (height <= max_height) {
						//不限制高度
						results = {
							"width": width,
							"height": height
						};
					} else {
						//限制高度
						results = {
							"width": height * rate,
							"height": height
						};
					}
				}
				resolve(res)
			},
			fail: function(error){
				reject(error)
			}
		})
	})
}

おすすめ

転載: blog.csdn.net/qq_27851967/article/details/90041757