diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2010-11-04 15:40:39 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2010-11-04 15:40:39 +1100 |
| commit | 348ae010bcea423b526d7945a5a8d9eb58c2a55c (patch) | |
| tree | c6370c1c07ff0b9c58cb054e31e095bc81293d2e /inc | |
| parent | a2a404f1daca791b0345ce76de3b3fcbd26d3004 (diff) | |
Aspect ratio for images
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/functions.php | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/inc/functions.php b/inc/functions.php index 1409c7b1..6ac50343 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -223,9 +223,33 @@ } } + // Highest common factor + function hcf($a, $b){ + $gcd = 1; + if ($a>$b) { + $a = $a+$b; + $b = $a-$b; + $a = $a-$b; + } + if ($b==(round($b/$a))*$a) + $gcd=$a; + else { + for($i=round($a/2);$i;$i--) { + if ($a == round($a/$i)*$i && $b == round($b/$i)*$i) { + $gcd = $i; + $i = false; + } + } + } + return $gcd; + } + function fraction($numerator, $denominator, $sep) { - $fraction = Array($numerator, $denominator); - return "{$fraction[0]}{$sep}{$fraction[1]}"; + $gcf = hcf($numerator, $denominator); + $numerator = $numerator / $gcf; + $denominator = $denominator / $gcf; + + return "{$numerator}{$sep}{$denominator}"; } /*********************************************/ |
