Skip to content

Commit 163b205

Browse files
committed
refactor: supports non-standard square ratio
1 parent 865c024 commit 163b205

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Providers/Models/DTO/ModelConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,12 @@ protected function validateMediaOrientationAspectRatioCompatibility(
729729
MediaOrientationEnum $orientation,
730730
string $aspectRatio
731731
): void {
732-
if ($orientation->isSquare() && $aspectRatio !== '1:1') {
732+
$aspectRatioParts = explode(':', $aspectRatio);
733+
if ($orientation->isSquare() && $aspectRatioParts[0] !== $aspectRatioParts[1]) {
733734
throw new InvalidArgumentException(
734735
'The aspect ratio "' . $aspectRatio . '" is not compatible with the square orientation.'
735736
);
736737
}
737-
$aspectRatioParts = explode(':', $aspectRatio);
738738
if ($orientation->isLandscape() && $aspectRatioParts[0] <= $aspectRatioParts[1]) {
739739
throw new InvalidArgumentException(
740740
'The aspect ratio "' . $aspectRatio . '" is not compatible with the landscape orientation.'

tests/unit/Providers/Models/DTO/ModelConfigTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,15 @@ public function testMediaOrientationAspectRatioCompatibilitySquare(): void
715715
$config->setOutputMediaOrientation(MediaOrientationEnum::square());
716716
}
717717

718+
public function testMediaOrientationAspectRatioCompatibilitySquareNonNormalized(): void
719+
{
720+
$config = new ModelConfig();
721+
$config->setOutputMediaOrientation(MediaOrientationEnum::square());
722+
$config->setOutputMediaAspectRatio('16:16');
723+
724+
$this->assertSame('16:16', $config->getOutputMediaAspectRatio());
725+
}
726+
718727
public function testMediaOrientationAspectRatioCompatibilityLandscape(): void
719728
{
720729
$config = new ModelConfig();

0 commit comments

Comments
 (0)