Created
November 15, 2022 13:14
-
-
Save danielhaim1/e5a314ce2afc529cb6fcf096d7d40105 to your computer and use it in GitHub Desktop.
Return the natural dimensions of an image.
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
/** | |
* Return the natural dimensions of an image. | |
* @string img - The image to get the dimensions of. | |
* @return {object} - The natural width of the image. | |
* @return {null} - If the image has no natural dimensions. | |
*/ | |
function getNaturalDimensions({ naturalWidth, naturalHeight }) { | |
// get the image format from the src attribute. | |
let width = naturalWidth; | |
let height = naturalHeight; | |
if (width && height) { | |
// return the natural width and height of the image. | |
return { width, height }; | |
} else { | |
// return null if the image has no natural dimensions. | |
return { width: null, height: null }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment