Created
November 15, 2011 07:01
-
-
Save kirkouimet/1366361 to your computer and use it in GitHub Desktop.
aspectRatioRounded
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
public static function aspectRatioRounded($a, $b) { | |
$total = $a + $b; | |
for($i = 1; $i <= 40; $i++) { | |
$arx = $i * 1.0 * $a / $total; | |
$brx = $i * 1.0 * $b / $total; | |
if($i == 40 || ( | |
abs($arx - round($arx)) <= 0.02 && | |
abs($brx - round($brx)) <= 0.02)) { | |
# Accept aspect ratios within a given tolerance | |
return round($arx).'x'.round($brx); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment