Skip to content

CLI support for image alt text generation #16

Description

@alaminfirdows

Summary

Implement WP-CLI command to generate alternative text for image attachments using the WordPress AI Client, following WordPress/ai#44.

What was added

New subcommand under wp ai generate:

wp ai generate alt-text <attachment_id>

Capabilities

  • Validates attachment exists and is image type
  • Converts image to data URI for vision model processing
  • Generates alt text via WordPress AI Client
  • Enforces 125-character limit (WCAG guideline)
  • Updates _wp_attachment_image_alt post meta
  • Supports all standard options: --provider, --model, --temperature, --top-p, --top-k, --max-tokens, --system-instruction

Example usage

$ wp ai generate alt-text 123
Success: Alt text generated and saved for attachment 123: A WordPress logo on a blue background

Implementation

  • Added generate_alt_text() private method to AI_Command class
  • Uses WordPress AI Client with_file() builder method for vision input
  • Error handling: missing attachment, non-image type, unreadable file, unsupported model
  • Test coverage: added Behat scenarios for error cases

Related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions