Last active
September 28, 2015 20:18
-
-
Save gravataLonga/1491669 to your computer and use it in GitHub Desktop.
aspect ratio of an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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