imageutil

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package imageutil holds shared image transforms for the model-bound image path. The one transform today is Downscale: cap an image's longest edge before it is inlined as a data_uri, so a full-resolution screenshot/PDF-page render doesn't cost full vision tokens on every provider call. It operates ONLY on the copy sent to the model — the on-disk materialized blob stays full resolution for the file tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Downscale

func Downscale(data []byte, maxEdge int) (out []byte, mime string, resized bool)

Downscale returns image bytes whose longest edge is <= maxEdge, re-encoded as PNG (lossless — preserves text/screenshots without artifacts). It is a best-effort no-op that returns the ORIGINAL bytes with resized=false when:

  • maxEdge <= 0 (feature off) or data is empty,
  • the bytes aren't a decodable image,
  • the image already fits within maxEdge, or
  • decode/scale/encode fails.

On a successful resize it returns the new bytes, mime "image/png", and true. The PNG byte size may exceed the source for a downscaled photo, but that doesn't matter for vision tokens (the model rasterizes by pixels, and the caller's byte-size caps still apply); reducing PIXELS is what cuts the token cost.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL