opencode-image-resizer
v0.1.3
Published
OpenCode plugin that automatically resizes images over 5MB before sending to Claude API
Maintainers
Readme
opencode-image-resizer
OpenCode plugin that automatically resizes images over 5MB before sending to the Claude API.
Problem
Claude API has a 5MB limit per image. When you reference images in OpenCode (via @file or drag-and-drop), images exceeding this limit cause errors.
Solution
This plugin intercepts image reads and automatically resizes them using a ratio-based heuristic: it calculates how much the image needs to shrink and applies quality/resolution reduction in a single shot — no slow iterative scanning.
Install
Add to your opencode.json:
{
"plugin": ["opencode-image-resizer"]
}Configuration
Set via environment variables (e.g., in your shell profile or .env):
| Variable | Default | Description |
|---|---|---|
| IMAGE_RESIZER_MAX_SIZE_MB | 4.5 | Images above this size (MB) are resized. Max 5.0. |
| IMAGE_RESIZER_MIN_QUALITY | 40 | Minimum JPEG quality (1–95). Plugin won't go below this. |
| IMAGE_RESIZER_MIN_SCALE | 0.25 | Minimum resolution scale (0.1–1.0). 1.0 = never reduce resolution. |
# Example: higher quality, never reduce resolution
export IMAGE_RESIZER_MIN_QUALITY=65
export IMAGE_RESIZER_MIN_SCALE=1.0How It Works
The plugin intercepts images at three points:
readtool (@filereferences): When the LLM reads an image file over the limitchat.message: When you drag-and-drop an image into the terminalresize_imagetool: Explicit LLM-callable tool for manual resizing
Resize Strategy
Given ratio = originalSize / maxSize, parameters are determined in one shot:
| ratio | quality | scale | Example | |---|---|---|---| | ≤ 1.1x | 93 | 100% | 5.0MB → 4.5MB | | ≤ 1.3x | 88 | 100% | 5.5MB → 4.5MB | | ≤ 1.6x | 83 | 100% | 7MB → 4.5MB | | ≤ 2.0x | 78 | 100% | 9MB → 4.5MB | | ≤ 2.5x | 72 | 95% | 11MB → 4.5MB | | ≤ 3.5x | 66 | 88% | 15MB → 4.5MB | | ≤ 5.0x | 58 | 80% | 22MB → 4.5MB | | ≤ 8.0x | 50 | 70% | 36MB → 4.5MB | | ≤ 15x | 45 | 55% | — | | 15x+ | 40 | 40% | — |
If the first attempt misses (edge case), a safety retry applies -15 quality and 80% scale. Maximum 3 attempts total.
For lossless formats (PNG, BMP, TIFF): lossless PNG re-compression is tried first (zero quality loss), then JPEG conversion with the heuristic above.
Supported Formats
jpg, jpeg, png, gif, webp, bmp, tiff, tif, avif
GIF: only the first frame is used.
resize_image Tool
Ask Claude directly when needed:
이 이미지가 너무 크면 resize_image 도구로 줄여줘: /path/to/image.pngSupports the same options as the env config, overridable per-call:
| Arg | Type | Default |
|---|---|---|
| filePath | string | required |
| maxSizeMB | number | IMAGE_RESIZER_MAX_SIZE_MB |
| minQuality | number | IMAGE_RESIZER_MIN_QUALITY |
| minScale | number | IMAGE_RESIZER_MIN_SCALE |
License
MIT
