Skip to content

Instantly share code, notes, and snippets.

@mramirid
Last active January 7, 2023 02:14
Show Gist options
  • Save mramirid/297b0e9d16e305aba6c39611696ffe45 to your computer and use it in GitHub Desktop.
Save mramirid/297b0e9d16e305aba6c39611696ffe45 to your computer and use it in GitHub Desktop.
Calculate the height of an image based on its aspect ratio and width
/**
* Calculate the height of an image based on its aspect ratio and width
* @param {number} width
* @param {number} ratioWidth
* @param {number} ratioHeight
* @returns the calculated height
*/
function getHeight(width, ratioWidth, ratioHeight) {
const ratio = width / ratioWidth;
const height = ratio * ratioHeight;
return height;
}
console.log(getHeight(328, 4, 1.5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment