moritz-sauer-13 / silverstripe-ai-alt-text
Generate alt text for images via OpenAI Api
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
pkg:composer/moritz-sauer-13/silverstripe-ai-alt-text
Requires
- openai-php/client: ^0.18.0
- purplespider/asset-alt-text: ^3
- silverstripe/framework: ^6
README
Generates alt texts for images via OpenAI Vision API. Integrates seamlessly into the SilverStripe 6 CMS AssetAdmin — a native FormAction button triggers AI-based generation and saves the result directly.
Requires purplespider/asset-alt-text for the AltText field on Image assets.
Requirements
- SilverStripe Framework ^6
- purplespider/asset-alt-text ^3
- openai-php/client ^0.18.0
- PHP 8.1+
Installation
composer require moritz-sauer-13/silverstripe-ai-alt-text
Then run:
vendor/bin/sake dev/build flush=1
Configuration
API Key (required)
Set the OpenAI API key via environment variable (recommended) or YAML config.
Option 1: Environment variable (.env file or server config)
OPENAI_API_KEY="sk-your-api-key-here"
Option 2: YAML config (app/_config/ai-alt-text.yml)
AiAltText\Service\OpenAiVisionClient: api_key: 'sk-your-api-key-here'
Note: Environment variables take precedence over YAML config.
Optional Configuration
# Model selection (default: gpt-4o-mini) AiAltText\Service\OpenAiVisionClient: model: 'gpt-4o' max_tokens: 300 # Image resize limits before sending to OpenAI (default: 1024x1024) AiAltText\Service\AltTextGenerator: max_image_width: 1024 max_image_height: 1024
Custom Prompt (SiteConfig)
The AI prompt can be customized directly in the CMS:
- Go to Settings in the CMS
- Click on the AI Alt Text tab
- Enter your custom prompt in the text field
- Save
The custom prompt allows you to:
- Set the output language directly (e.g., "Write in German" or "Schreibe auf Deutsch")
- Customize the style and length of generated alt texts
- Add specific instructions for your content type
Example custom prompt (German):
Schreibe einen prägnanten, beschreibenden Alt-Text für dieses Bild auf Deutsch.
Regeln:
- Länge: 80-160 Zeichen, kürzer bei einfachen Bildern.
- Sei spezifisch und beschreibend.
- Beginne nicht mit "Bild von", "Foto von" oder ähnlichen Phrasen.
- Keine Marketing-Sprache.
- Gib NUR den Alt-Text zurück, nichts anderes.
Leave the field empty to use the default English prompt.
License
BSD-3-Clause