/** 计算把图片放入容器时,重设尺寸后大小与位置 */ export function calcResizePostion( src: { w: number; h: number }, to: { w: number; h: number }, type: "center" | "left" = "left" ) { let scaleW = to.w / src.w let scaleH = to.h / src.h let s = Math.min(scaleW, scaleH) let w = Math.round(src.w * s) let h = Math.round(src.h * s) let x = 0 let y = 0 if (type == "center") { x = Math.round((to.w - w) / 2) y = Math.round((to.h - h) / 2) } return { x, y, h, w } }