WordPress\AiClient\Providers\Models\DTO

ModelConfig::validateMediaOrientationAspectRatioCompatibilityprotectedWP 0.4.0

Validates that the given media orientation and aspect ratio values do not conflict with each other.

Method of the class: ModelConfig{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->validateMediaOrientationAspectRatioCompatibility( $orientation, $aspectRatio ): void;
$orientation(MediaOrientationEnum) (required)
The desired media orientation.
$aspectRatio(string) (required)
The desired media aspect ratio.

Changelog

Since 0.4.0 Introduced.

ModelConfig::validateMediaOrientationAspectRatioCompatibility() code WP 7.0

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.');
    }
}