Last active
June 29, 2017 21:12
-
-
Save lucymtc/ac42fc7a07734492ae5e2a7baec63deb to your computer and use it in GitHub Desktop.
Get aspect ratio for an image
This file contains hidden or 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 | |
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); | |
} | |
/** | |
Usage: | |
$img_width = 250; | |
$img_height = 250; | |
$aspect_ratio = ratio( 250, 250 ); | |
echo $aspect_ratio; // 1:1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment