Uh oh!
There was an error while loading. Please reload this page.
feat: auto-convert unsupported image formats (AVIF, HEIC) to PNG - #17774
feat: auto-convert unsupported image formats (AVIF, HEIC) to PNG#17774RaviTharuma wants to merge 1 commit into
Conversation
AI provider APIs (Anthropic, OpenAI, Google) only support a limited set of image formats (PNG, JPEG, GIF, WebP). When users paste or reference images in formats like AVIF, HEIC, HEIF, JXL, TIFF, or BMP, the API returns an error. This adds transparent image conversion in File.read(): - Detects unsupported image formats before base64 encoding - Converts to PNG using sharp (optional dep) or system tools (sips on macOS, ffmpeg as cross-platform fallback) - Falls back gracefully to original format if no converter is available - Adds AVIF/HEIC/HEIF to TUI MIME_BADGE display map Closesanomalyco#17772 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
rekram1-node
commented
May 15, 2026
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes#17772
Also addresses #12519 and #10609 (same root cause — unsupported image formats hitting provider APIs)
Type of change
What does this PR do?
AI provider APIs (Anthropic, OpenAI, Google) only accept PNG, JPEG, GIF, and WebP images. When users reference AVIF, HEIC, TGA, or other unsupported files, the API returns a 400 error like
image/avif is not a supported media type.This adds transparent conversion in
File.read()— when an image has an unsupported MIME type (AVIF, HEIC, HEIF, JXL, TIFF, BMP), it converts to PNG before base64-encoding. The conversion uses a 3-tier fallback:sharp(added as optional dependency — fast, cross-platform)sips(always available on macOS)ffmpeg(cross-platform fallback)If none are available, the original format is sent as-is (same as current behavior — no regression).
Also adds AVIF/HEIC/HEIF entries to the TUI
MIME_BADGEmap so these formats display the "img" badge.How did you verify your code works?
sipson macOS using real AVIF web assetsScreenshots / recordings
N/A — no UI change beyond badge labels.
Checklist