0

If I have an image that is 2550x3300 pixels and another one that is 773x1000 pixels, how would I compare both images aspect-ratios in PHP? Both images should have the same aspect ratio since I resized it in paint.net with the "maintain aspect ratio" box clicked. But I've used various PHP attempts to figure out the aspect-ratio of each image and they come out different.

4

1 回答 1

0

计算Aspect Ratio in PHP

function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

  $gcd=gcd(1024,768);

  echo "Aspect ratio = ". (2550/$gcd) . ":" . (3300/$gcd);
于 2013-10-03T05:34:38.143 回答