Validates that the given media orientation and aspect ratio values do not conflict with each other.
Parameters
$orientationWordPressAiClientFilesEnumsMediaOrientationEnumrequired- The desired media orientation.
$aspectRatiostringrequired- The desired media aspect ratio.
Source
protected function validateMediaOrientationAspectRatioCompatibility(MediaOrientationEnum $orientation, string $aspectRatio): void
{
$aspectRatioParts = explode(':', $aspectRatio);
if ($orientation->isSquare() && $aspectRatioParts[0] !== $aspectRatioParts[1]) {
throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not compatible with the square orientation.');
}
if ($orientation->isLandscape() && $aspectRatioParts[0] <= $aspectRatioParts[1]) {
throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not compatible with the landscape orientation.');
}
if ($orientation->isPortrait() && $aspectRatioParts[0] >= $aspectRatioParts[1]) {
throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not compatible with the portrait orientation.');
}
}
Changelog
| Version | Description |
|---|---|
| 0.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.