Created
March 25, 2017 17:26
-
-
Save gauravmehla/583349e5127ec292bd95b371abe8e3e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html><body> | |
<script type="text/javascript"> | |
// Used to scale image according to aspect ratio | |
function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) { | |
var ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight); | |
return { width: srcWidth*ratio, height: srcHeight*ratio }; | |
} | |
// Calculate aspect ratio | |
function gcd (a, b) { | |
return (b == 0) ? a : gcd (b, a%b); | |
} | |
var w = screen.width; | |
var h = screen.height; | |
var r = gcd (w, h); | |
document.write ("<pre>"); | |
document.write ("Dimensions = ", w, " x ", h, "<br>"); | |
document.write ("Gcd = ", r, "<br>"); | |
document.write ("Aspect = ", w/r, ":", h/r); | |
document.write ("</pre>"); | |
</script> | |
</body></html> | |
<!-- | |
Example : | |
Dimensions = 1280 x 960 | |
Gcd = 320 | |
Aspect = 4:3 | |
Dimensions = 1920 x 1080 | |
Gcd = 120 | |
Aspect = 16:9 | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment