Documentation
¶
Overview ¶
Image resize + re-encode policy for CLI/LLM image attachments, plus the EXIF orientation reader (upstream exif-orientation.ts). PNG conversion for Kitty (upstream image-convert.ts) lives in image_convert.go.
Mirrors upstream packages/coding-agent/src/utils/image-resize.ts using the Go standard library plus golang.org/x/image in place of Photon:
- Decode + apply EXIF orientation once.
- If needed, resize to fit within 2000x2000.
- Try PNG first, then JPEG quality steps until the base64 payload fits under 4.5 MB.
- If still too large, shrink dimensions by 25% and retry.
Index ¶
- Constants
- Variables
- func ConvertImageBytesToPng(data []byte) []byte
- func DecodeNodeBase64(data string) []byte
- func DetectSupportedImageMimeType(buffer []byte) string
- func DetectSupportedImageMimeTypeFromFile(filePath string) string
- func NormalizeToolResultImages(result agent.AgentToolResult, autoResize bool) agent.AgentToolResult
- func NormalizeToolResultImagesWithOptions(result agent.AgentToolResult, autoResize bool, ...) agent.AgentToolResult
- func PrepareCLIImageAttachment(in []byte, inputMIME string) ([]byte, string, string, error)
- func ProcessImage(in []byte, inputMIME string, autoResize bool, ...) ([]byte, string, string, error)
- func ResizeImageForLLM(in []byte) ([]byte, string, error)
Constants ¶
const ( MaxLongestSide = 2000 MaxEncodedBytes = int(4.5 * 1024 * 1024) // base64 payload bytes JPEGQuality = 80 )
const ImageTypeSniffBytes = 4100
ImageTypeSniffBytes mirrors upstream IMAGE_TYPE_SNIFF_BYTES: detection looks only at a file's first 4100 bytes.
Variables ¶
var ErrImageTooLarge = errors.New("image: could not be resized below inline image size limit")
Functions ¶
func ConvertImageBytesToPng ¶
ConvertImageBytesToPng applies EXIF orientation before encoding PNG, as upstream image-convert.ts does through Photon. Failure returns nil.
func DecodeNodeBase64 ¶
DecodeNodeBase64 mirrors Node's Buffer.from(data, "base64"): it accepts the standard and URL-safe alphabets, skips every other character (whitespace included), stops at the first '=', and decodes a trailing partial quantum of two or three characters to one or two bytes.
func DetectSupportedImageMimeType ¶
DetectSupportedImageMimeType mirrors upstream mime.ts and returns a supported still-image MIME type for the provided bytes, or "" when unsupported.
The formats named here are also the only decoders this package links, so a format outside the allowlist has no decoder to reach. Adding a MIME type here or to tools.SupportedImageMime without adding its decoder import decodes nothing; adding the decoder import widens the attack surface of the image pipeline to that format's parser.
func DetectSupportedImageMimeTypeFromFile ¶
DetectSupportedImageMimeTypeFromFile reads the upstream sniff window from a file and returns the supported still-image MIME type, or "" when unsupported.
func NormalizeToolResultImages ¶
func NormalizeToolResultImages(result agent.AgentToolResult, autoResize bool) agent.AgentToolResult
NormalizeToolResultImages processes data images as they enter history. With auto-resize enabled, oversized images are resized once; disabled, unsupported still-image formats are still converted to a supported inline format (no resize): mirroring upstream processImage, whose normalizeImage step runs before the auto-resize branch. Decode/processing failures preserve the original block; conversion and resize hints are appended to the tool result.
func NormalizeToolResultImagesWithOptions ¶
func NormalizeToolResultImagesWithOptions(result agent.AgentToolResult, autoResize bool, options *ai.ModelImageResizeOptions) agent.AgentToolResult
NormalizeToolResultImagesWithOptions applies the active model profile after extension hooks. Failed image processing retains the original image block.
func PrepareCLIImageAttachment ¶
PrepareCLIImageAttachment processes one CLI image file into the attached image payload plus the upstream dimension note (empty when not resized).
func ProcessImage ¶
func ProcessImage(in []byte, inputMIME string, autoResize bool, options *ai.ModelImageResizeOptions) ([]byte, string, string, error)
ProcessImage normalizes unsupported formats before applying a model's resize profile. A false autoResize flag still converts unsupported formats. Errors carry upstream's omission hint; callers decide whether to keep a tool image.
Types ¶
This section is empty.