这个函数是为了实现图片按比例缩放的功能,确保图像在指定的尺寸范围内进行优化显示。
具体函数如下
export const getImgWidthHeight = (imgWidth, imgHeight) => {
const maxDimension = 150;
const minDimension = 30;
let width = Math.min(imgWidth, maxDimension);
let height = Math.min(imgHeight, maxDimension);
if (imgWidth > imgHeight && imgWidth > maxDimension) {
height = (maxDimension / imgWidth) * imgHeight;
} else if (imgHeight > imgWidth && imgHeight > maxDimension) {
width = (maxDimension / imgHeight) * imgWidth;
}
width = Math.max(width, minDimension);
height = Math.max(height, minDimension);
return {
width,
height
};
};
阅读进度 0%
private note
交流
文章暂不开放公开评论。如果你有想法、问题或建议,欢迎私下联系站长。
联系站长 →