el-schneider/statamic-auto-alt-text 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

el-schneider/statamic-auto-alt-text

Composer 安装命令:

composer require el-schneider/statamic-auto-alt-text

包简介

README 文档

README

Auto Alt Text

Statamic Auto Alt Text

Automatically generate descriptive alt text for images in Statamic v5 using AI services via Prism PHP

⚠️ Upgrading from v0.x?

Breaking Changes in v1.0: Moondream support has been removed. If you were using Moondream, switch to Ollama with a vision model like llava for local processing, or choose from 7+ cloud providers (OpenAI, Anthropic, etc.).

Migration is simple: Replace your old config with the new AUTO_ALT_TEXT_MODEL format:

# Old (v0.x)
AUTO_ALT_TEXT_SERVICE=openai
OPENAI_MODEL=gpt-4.1

# New (v1.x)
AUTO_ALT_TEXT_MODEL=openai/gpt-4.1

See Upgrading from v0.x for full details.

Features

  • Automatic Generation: Generate alt text for assets using AI by listening for Statamic asset events
  • Multiple AI Providers: Support for OpenAI, Anthropic, Ollama, Mistral, Groq, DeepSeek, and xAI via Prism PHP
  • Data Privacy: Option to use local Ollama endpoints, keeping image data within your infrastructure
  • Asset Filtering: Exclude sensitive or private assets from processing with global patterns, container-specific rules, or individual asset settings
  • Control Panel Integration: Field Action to generate alt text for individual images
  • Bulk Processing: Artisan Command for processing images individually or in batch

Installation

composer require el-schneider/statamic-auto-alt-text

Publish the configuration file:

php artisan vendor:publish --tag="statamic-auto-alt-text-config"

Configuration

Configure your AI provider in .env:

# Model format: provider/model-name
AUTO_ALT_TEXT_MODEL=openai/gpt-4.1

# API key (managed by Prism - see config/prism.php)
OPENAI_API_KEY=your_api_key_here

Supported Providers

Provider Example Model Environment Variable
OpenAI openai/gpt-4.1 OPENAI_API_KEY
Anthropic anthropic/claude-sonnet-4-5 ANTHROPIC_API_KEY
Ollama ollama/llava (local, no key needed)
Mistral mistral/pixtral-large-latest MISTRAL_API_KEY
Groq groq/llava-v1.5-7b-4096-preview GROQ_API_KEY
DeepSeek deepseek/deepseek-chat DEEPSEEK_API_KEY
xAI xai/grok-vision-beta XAI_API_KEY

Custom Providers

You can use any custom provider supported by Prism. First, register your custom provider in a service provider:

use App\Prism\Providers\MyCustomProvider;

public function boot(): void
{
    $this->app['prism-manager']->extend('my-provider', function ($app, $config) {
        return new MyCustomProvider(apiKey: $config['api_key']);
    });
}

Then configure it in your .env:

AUTO_ALT_TEXT_MODEL=my-provider/model-name

See Prism's Custom Providers documentation for details on building and registering custom providers.

For advanced provider configuration (custom endpoints, timeouts, etc.), publish Prism's config:

php artisan vendor:publish --tag="prism-config"

Non-English Captions

You can customize the prompt to generate captions in your preferred language:

AUTO_ALT_TEXT_PROMPT="Beschreibe dieses Bild kurz und bündig, um einen Alternativtext für Barrierefreiheit bereitzustellen."
AUTO_ALT_TEXT_SYSTEM_MESSAGE="Du bist ein Barrierefreiheitsexperte, der kurze, beschreibende Alt-Texte für Bilder generiert. Antworte nur mit dem Alt-Text, ohne Einleitung oder Erklärungen."

Usage

Automatic Generation

The addon listens for configured Statamic events (default: AssetUploaded and AssetSaving). When an asset without alt text is detected, a background job is dispatched to generate it automatically using your configured AI service.

Important: This feature requires Laravel's queue system with an asynchronous queue driver (e.g., database, redis, sqs) and a running queue worker (php artisan queue:work). The default sync driver won't work for background processing.

Optionally customize the queue configuration:

# Optional: Defaults to your application's default queue connection
AUTO_ALT_TEXT_QUEUE_CONNECTION=redis

# Optional: Defaults to the default queue name for the connection
AUTO_ALT_TEXT_QUEUE_NAME=alt_text_generation

Manual Generation

For existing assets or specific workflows:

  1. Field Action: Edit an asset, find the alt text field, and click the "Generate Alt Text" action
  2. Statamic Action: In an Asset container, use the "Generate Alt Text" action from the contextual menu
  3. CLI Command: Process assets in bulk with:
php please auto-alt:generate

See php please auto-alt:generate --help for options to specify containers, assets, and overwriting behavior

Using Local Ollama

For privacy or compliance reasons, you can run vision models locally with Ollama:

  1. Set up Ollama: Install Ollama and pull a vision model: ollama pull llava
  2. Configure the addon:
AUTO_ALT_TEXT_MODEL=ollama/llava
  1. Configure Prism: Publish Prism's config and set the Ollama endpoint:
php artisan vendor:publish --tag="prism-config"

Then update config/prism.php:

'ollama' => [
    'url' => env('OLLAMA_URL', 'http://localhost:11434'),
],

Generation Parameters

Fine-tune the AI generation with these environment variables:

AUTO_ALT_TEXT_MAX_TOKENS=100      # Maximum length of generated text
AUTO_ALT_TEXT_TEMPERATURE=0.7     # Creativity (0.0 = deterministic, 1.0 = creative)
AUTO_ALT_TEXT_TIMEOUT=60          # Request timeout in seconds

Upgrading from v0.x

If upgrading from v0.x, update your environment variables:

Before (v0.x)

AUTO_ALT_TEXT_SERVICE=openai
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4.1
OPENAI_ENDPOINT=https://api.openai.com/v1/chat/completions

After (v1.x)

AUTO_ALT_TEXT_MODEL=openai/gpt-4.1
OPENAI_API_KEY=sk-...

Breaking changes:

  • Moondream support has been removed (use Ollama with llava for local processing)
  • Config structure simplified: services.openai.* replaced with flat model setting
  • Environment variables changed: AUTO_ALT_TEXT_MODEL replaces AUTO_ALT_TEXT_SERVICE

el-schneider/statamic-auto-alt-text 适用场景与选型建议

el-schneider/statamic-auto-alt-text 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.04k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 el-schneider/statamic-auto-alt-text 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 el-schneider/statamic-auto-alt-text 我们能提供哪些服务?
定制开发 / 二次开发

基于 el-schneider/statamic-auto-alt-text 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-05-04