Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ui-component-library / src / playground / Image / deps / calculateAspectRatio.ts
Size: Mime:
/**
 * Conserve aspect ratio of the orignal region. Useful when shrinking/enlarging
 * images to fit into a certain area.
 *
 * @param {number} srcWidth width of source image
 * @param {number} srcHeight height of source image
 * @param {number} maxWidth maximum available width
 * @param {number} maxHeight maximum available height
 * @returns {object} { width, height }
 */
function calculateAspectRatio(
  srcWidth: number,
  srcHeight: number,
  maxWidth: number,
  maxHeight: number
) {
  const ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight)
  return {
    width: srcWidth * ratio,
    height: srcHeight * ratio,
  }
}

export { calculateAspectRatio }
export default calculateAspectRatio