Last active
January 7, 2023 02:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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