Documentation
¶
Overview ¶
Package imageresize shrinks inline images to fit the provider request-size limits, mirroring the upstream coding-agent image-resize behaviour with a stdlib-only implementation (PNG/JPEG/GIF decode, area-averaging downscale, PNG/JPEG re-encode). It is depended on by both the @file CLI path and the read tool, and intentionally lives in its own leaf package so packages/ai stays at the bottom of the dependency DAG.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DimensionNote ¶
DimensionNote returns the note that maps resized-image coordinates back to the original, or "" when the image was not resized. It mirrors the upstream formatDimensionNote string exactly.
Types ¶
type Options ¶
type Options struct {
MaxWidth int // default 2000
MaxHeight int // default 2000
MaxBytes int // default 4.5MB of base64 payload (below Anthropic's 5MB limit)
JPEGQuality int // default 80
}
Options controls Resize. Zero fields fall back to the defaults that mirror the upstream image-resize-core defaults.
type Result ¶
type Result struct {
Data string
MimeType string
OriginalWidth int
OriginalHeight int
Width int
Height int
WasResized bool
}
Result is the outcome of Resize: base64 data plus the dimensions before/after, mirroring the upstream ResizedImage shape.
func Resize ¶
Resize shrinks an image to fit within the configured max dimensions and base64 payload size, returning nil when it cannot be brought under MaxBytes. It is a stdlib port of the upstream resizeImageInProcess: try the original if it already fits, otherwise downscale to the max box and pick the smallest of PNG / decreasing-quality JPEG, progressively reducing dimensions if needed.
Inputs whose format the standard library cannot decode (e.g. WebP) are passed through unchanged when already under MaxBytes, or omitted (nil) when not.