Skip to content

Instantly share code, notes, and snippets.

@lucymtc
Last active June 29, 2017 21:12
Show Gist options
  • Save lucymtc/ac42fc7a07734492ae5e2a7baec63deb to your computer and use it in GitHub Desktop.
Save lucymtc/ac42fc7a07734492ae5e2a7baec63deb to your computer and use it in GitHub Desktop.
Get aspect ratio for an image
<?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