WordPress\AiClient\Providers\OpenAiCompatibleImplementation

AbstractOpenAiCompatibleImageGenerationModel::prepareSizeParamprotectedWP 0.1.0

Prepares the size parameter for the API request.

Method of the class: AbstractOpenAiCompatibleImageGenerationModel{}

No Hooks.

Returns

String. The prepared size parameter.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepareSizeParam( ?MediaOrientationEnum $orientation, ?string $aspectRatio ): string;
?MediaOrientationEnum $orientation(required)
.
?string $aspectRatio(required)
.

Changelog

Since 0.1.0 Introduced.

AbstractOpenAiCompatibleImageGenerationModel::prepareSizeParam() code WP 7.0

protected function prepareSizeParam(?MediaOrientationEnum $orientation, ?string $aspectRatio): string
{
    // Use aspect ratio if set, as it is more specific.
    if ($aspectRatio !== null) {
        switch ($aspectRatio) {
            case '1:1':
                return '1024x1024';
            case '3:2':
                return '1536x1024';
            case '7:4':
                return '1792x1024';
            case '2:3':
                return '1024x1536';
            case '4:7':
                return '1024x1792';
            default:
                throw new InvalidArgumentException('The aspect ratio "' . $aspectRatio . '" is not supported.');
        }
    }
    // This should always have a value, as the method is only called if at least one or the other is set.
    if ($orientation !== null) {
        if ($orientation->isLandscape()) {
            return '1536x1024';
        }
        if ($orientation->isPortrait()) {
            return '1024x1536';
        }
    }
    return '1024x1024';
}