Last active
October 16, 2023 18:43
-
-
Save amnuts/d44e97089df783fff06c to your computer and use it in GitHub Desktop.
Aspect ratio from width/height
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
<?php | |
function ratio($a, $b) | |
{ | |
$gcd = function($a, $b) use (&$gcd) { | |
return ($a % $b) ? $gcd($b, $a % $b) : $b; | |
}; | |
$g = $gcd($a, $b); | |
return $a/$g . ':' . $b/$g; | |
} | |
echo ratio(1920, 1080); // 16:9 | |
echo "\n"; | |
echo ratio(640, 480); // 4:3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment