const getStandardRatio = (width, height, widthRatio = 16, heightRatio = 9) => { // 实际宽高比 const computedRatio = width / height; // 标准宽高比 const standardRatio = widthRatio / heightRatio; // 以高为准 if (computedRatio >= standardRatio) { const computedWidth = (height * widthRatio) / heightRatio; return { width: computedWidth, height, }; } // 以宽为准 const computedHeight = (width * heightRatio) / widthRatio; return { width, height: computedHeight, }; };