Created
December 18, 2015 19:37
-
-
Save vanrez-nez/defef8de6110ac9239d9 to your computer and use it in GitHub Desktop.
Image resizing utils
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
function getSizeToCover(width, height, maxWidth, maxHeight) { | |
var ratio = Math.max(maxWidth / width, maxHeight / height); | |
return { | |
width: width * ratio, | |
height: height * ratio | |
}; | |
} | |
function getSizeToContain(width, height, maxWidth, maxHeight) { | |
var ratio = Math.min(maxWidth / width, maxHeight / height); | |
return { | |
width: width * ratio, | |
height: height * ratio | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment