This commit is contained in:
ct
2025-06-20 13:03:52 +08:00
parent eef45fdc9d
commit b502120091
22 changed files with 426 additions and 164 deletions

View File

@@ -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;
}
}