# auto-alt-text/2.1.0/src/App/AltTextGeneratorAi.php

Auto Alt Text, version 2.1.0. 38 lines.

- Page: https://pluginprobe.com/plugins/auto-alt-text/2.1.0/code/src/App/AltTextGeneratorAi.php
- Raw: https://pluginprobe.com/plugins/auto-alt-text/2.1.0/raw/src/App/AltTextGeneratorAi.php
- Modified: 2024-03-10T14:55:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/auto-alt-text/2.1.0/code/src/App/AltTextGeneratorAi.php#L10-L20`.

```php
<?php

namespace AATXT\App;

use AATXT\App\AIProviders\AIProviderInterface;

class AltTextGeneratorAi implements AltTextGeneratorInterface
{
    private AIProviderInterface $AIProvider;

    /**
     * @param AIProviderInterface $AIProvider
     */
    private function __construct(AIProviderInterface $AIProvider)
    {
        $this->AIProvider = $AIProvider;
    }

    /**
     * @param AIProviderInterface $aiProvider
     * @return AltTextGeneratorAi
     */
    public static function make(AIProviderInterface $aiProvider): AltTextGeneratorAi
    {
        return new self($aiProvider);
    }

    /**
     * Get the alt text of the image
     * @param int $imageId
     * @return string
     */
    public function altText(int $imageId): string
    {
        $imageUrl = wp_get_attachment_url($imageId);
        return $this->AIProvider->response($imageUrl);
    }
}
```
