Skip to content

Instantly share code, notes, and snippets.

@kirkouimet
Created November 15, 2011 07:01
Show Gist options
  • Save kirkouimet/1366361 to your computer and use it in GitHub Desktop.
Save kirkouimet/1366361 to your computer and use it in GitHub Desktop.
aspectRatioRounded
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