PHP code example of soderlind / ai-alt-text
1. Go to this page and download the library: Download soderlind/ai-alt-text library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
soderlind / ai-alt-text example snippets
// AI Provider: 'openai', 'anthropic', 'gemini', 'azure', 'ollama', 'grok'
define( 'AI_ALT_TEXT_PROVIDER', 'openai' );
// API Key
define( 'AI_ALT_TEXT_API_KEY', 'your-api-key-here' );
// Optional: Custom model
define( 'AI_ALT_TEXT_MODEL', 'gpt-4o' );
// Azure-specific settings
define( 'AI_ALT_TEXT_AZURE_ENDPOINT', 'https://your-resource.openai.azure.com' );
define( 'AI_ALT_TEXT_AZURE_DEPLOYMENT', 'your-deployment-name' );
// Ollama-specific settings
define( 'AI_ALT_TEXT_OLLAMA_HOST', 'http://localhost:11434' );
add_filter( 'ai_alt_text_generated', function( $alt_text, $attachment_id ) {
// Modify the generated alt text
return $alt_text;
}, 10, 2 );
add_filter( 'ai_alt_text_prompt', function( $prompt, $language ) {
// Customize the prompt sent to the AI
return $prompt;
}, 10, 2 );
add_filter( 'ai_alt_text_should_generate', function( $should_generate, $attachment_id ) {
// Return false to skip auto-generation
return $should_generate;
}, 10, 2 );
bash
# Check PHP code standards
./vendor/bin/phpcs
# Fix PHP code standards
./vendor/bin/phpcbf