Skip to content

Instantly share code, notes, and snippets.

@amnuts
Last active October 16, 2023 18:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amnuts/d44e97089df783fff06c to your computer and use it in GitHub Desktop.
Save amnuts/d44e97089df783fff06c to your computer and use it in GitHub Desktop.
Aspect ratio from width/height
<?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