Update
This commit is contained in:
@@ -4,20 +4,19 @@
|
||||
|
||||
class AspectRatio
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the aspect ratio for given width and height
|
||||
* Returns common aspect ratios first, then computed ratios
|
||||
*
|
||||
* @param int|float $width
|
||||
* @param int|float $height
|
||||
* @param int|float $width
|
||||
* @param int|float $height
|
||||
* @return string
|
||||
*/
|
||||
public static function get($width, $height)
|
||||
{
|
||||
// Handle edge cases
|
||||
if ($width <= 0 || $height <= 0) {
|
||||
return "Invalid dimensions";
|
||||
return 'Invalid dimensions';
|
||||
}
|
||||
|
||||
// Calculate the actual ratio
|
||||
@@ -53,8 +52,8 @@ public static function get($width, $height)
|
||||
/**
|
||||
* Compute simplified aspect ratio using GCD
|
||||
*
|
||||
* @param int|float $width
|
||||
* @param int|float $height
|
||||
* @param int|float $width
|
||||
* @param int|float $height
|
||||
* @return string
|
||||
*/
|
||||
private static function computeSimplifiedRatio($width, $height)
|
||||
@@ -70,14 +69,14 @@ private static function computeSimplifiedRatio($width, $height)
|
||||
$simplifiedWidth = $intWidth / $gcd;
|
||||
$simplifiedHeight = $intHeight / $gcd;
|
||||
|
||||
return $simplifiedWidth . ':' . $simplifiedHeight;
|
||||
return $simplifiedWidth.':'.$simplifiedHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Greatest Common Divisor using Euclidean algorithm
|
||||
*
|
||||
* @param int $a
|
||||
* @param int $b
|
||||
* @param int $a
|
||||
* @param int $b
|
||||
* @return int
|
||||
*/
|
||||
private static function gcd($a, $b)
|
||||
@@ -88,6 +87,7 @@ private static function gcd($a, $b)
|
||||
$b = $a % $b;
|
||||
$a = $temp;
|
||||
}
|
||||
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user