Image Descriptor
A VSCode/Cursor extension that generates accessible alternative text for images using AI (OpenAI GPT-4o).
Features
- Right-click context menu integration for HTML files
- Supports both absolute URLs and relative file paths
- Automatically converts local images to base64 for AI processing
- Uses OpenAI's GPT-4o model for accurate image descriptions
- Follows web accessibility best practices for alt text generation
Installation
From the VSCode Marketplace
- Open VSCode or Cursor
- Go to the Extensions panel (Cmd/Ctrl + Shift + X)
- Search for Image Descriptor
- Click Install
Manual Installation (Advanced)
If you want to install from a .vsix file:
- Download the latest
.vsix file
- In VSCode/Cursor, run:
code --install-extension image-descriptor-<version>.vsix
Configuration
Each user must provide their own OpenAI API key.
- Get an API key from your chosen provider
- In VSCode/Cursor, open the extension page
- Click on the settings (gear) icon to open the extension settings
- Choose your preferred provider from the dropdown
- Enter your chosen provider API key in the
imageDescriptor.providerApiKey field
Note: You can also search for @ext:schalkneethling.image-descriptor in VSCode's settings
Usage
- Open an HTML file containing an
<img> element
- Place your cursor inside the
alt="" attribute (or where you want to add it)
- Right-click to open the context menu
- Select Image Descriptor: Suggest alternative text
- The extension will:
- Extract the image source from the
src attribute
- Process the image (URL or local file)
- Generate accessible alt text using AI
- Insert the generated text into the
alt attribute
How it Works
- Absolute URLs: Uses the URL directly
- Relative paths: Converts local images to base64 data URLs
- File support: PNG, JPEG, GIF, WebP, SVG
- AI Integration: Uses OpenAI's GPT-4o model (vision + text)
- Accessibility: Follows best practices for concise, descriptive alt text
Troubleshooting
- "No img element found": Make sure your cursor is inside an
<img> tag
- "No src attribute found": Ensure the image has a
src attribute
- API key errors: Verify your OpenAI API key is correctly configured and you have credits
- File not found: Check that relative paths are correct relative to the HTML file
- Model errors: Make sure you are using the correct model name (
gpt-4o ) and your API key has access
Debug Mode
To enable debug logging:
- Open Command Palette (Cmd/Ctrl + Shift + P)
- Type "Developer: Toggle Developer Tools"
- Check the Console tab for detailed logs
Development (for advanced users)
- Clone the repository
- Install dependencies:
npm install
- Compile the extension:
npm run compile
- Press
F5 in VSCode to launch the Extension Development Host
Contributing
See CONTRIBUTING.md for guidelines on contributing to this project.
License
MIT License
| |