I can\'t believe I can\'t find the formula for this. I am using a PHP script called SLIR to resize images. The script asks to specify an aspect ratio for cropping. I\'d like
Here's a much simpler alternative for greatest common divisor integer ratios:
function ratio( $x, $y ){
$gcd = gmp_strval(gmp_gcd($x, $y));
return ($x/$gcd).':'.($y/$gcd);
}
The request echo ratio(25,5); returns 5:1.
If your server wasn't compiled with GMP functions ...
function gcd( $a, $b ){
return ($a % $b) ? gcd($b,$a % $b) : $b;
}
function ratio( $x, $y ){
$gcd = gcd($x, $y);
return ($x/$gcd).':'.($y/$gcd);
}