Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <html><body>
  2. <script type="text/javascript">
  3.  
  4. // Used to scale image according to aspect ratio
  5. function calculateAspectRatioFit(srcWidth, srcHeight, maxWidth, maxHeight) {
  6. var ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight);
  7. return { width: srcWidth*ratio, height: srcHeight*ratio };
  8. }
  9.  
  10. // Calculate aspect ratio
  11. function gcd (a, b) {
  12. return (b == 0) ? a : gcd (b, a%b);
  13. }
  14. var w = screen.width;
  15. var h = screen.height;
  16. var r = gcd (w, h);
  17. document.write ("<pre>");
  18. document.write ("Dimensions = ", w, " x ", h, "<br>");
  19. document.write ("Gcd = ", r, "<br>");
  20. document.write ("Aspect = ", w/r, ":", h/r);
  21. document.write ("</pre>");
  22. </script>
  23. </body></html>
  24. <!--
  25. Example :
  26.  
  27. Dimensions = 1280 x 960
  28. Gcd = 320
  29. Aspect = 4:3
  30.  
  31. Dimensions = 1920 x 1080
  32. Gcd = 120
  33. Aspect = 16:9
  34. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement