Skip to content

Instantly share code, notes, and snippets.

@gravataLonga
Last active September 28, 2015 20:18
Show Gist options
  • Save gravataLonga/1491669 to your computer and use it in GitHub Desktop.
Save gravataLonga/1491669 to your computer and use it in GitHub Desktop.
aspect ratio of an image
<?php
// Exists functions gmp_gcd ?
if(!function_exists('gmp_gcd')){
// No, so create
// find greatest common divisor
function gmp_gcd($a, $b) {
while ($b != 0)
$remainder = $a % $b;
$a = $b;
$b = $remainder;
}
return abs ($a);
}
}
// Provide a two argument and return an array with two value,
// for exemple [3:1]
function ration_image ($width, $height){
$gcd = gmp_gcd($width, $height);
$width = $width/$gcd;
$height = $height/$gcd;
return array($width,$height);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment