imageprep

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package imageprep validates and normalizes raster images before they enter provider-independent model content.

Index

Constants

View Source
const (
	DefaultMaxInputBytes  int64 = 10 << 20
	DefaultMaxPixels      int64 = 40_000_000
	DefaultMaxDimension         = 2048
	DefaultMaxOutputBytes int64 = 10 << 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    ErrorCode
	Message string
	Cause   error
}

Error is a preparation failure with a safe public message and stable code.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorCode

type ErrorCode string

ErrorCode is a stable machine-readable preparation failure category.

const (
	ErrorInvalid       ErrorCode = "image_invalid"
	ErrorUnsupported   ErrorCode = "image_unsupported"
	ErrorTypeMismatch  ErrorCode = "image_type_mismatch"
	ErrorTooLarge      ErrorCode = "image_too_large"
	ErrorTooManyPixels ErrorCode = "image_too_many_pixels"
	ErrorAnimated      ErrorCode = "image_animated"
	ErrorCancelled     ErrorCode = "image_cancelled"
)

func CodeOf

func CodeOf(err error) ErrorCode

CodeOf returns the structured code carried by err, if any.

type Input

type Input struct {
	Data         []byte
	DeclaredMIME string
}

Input is one complete encoded raster and optional caller-declared media type.

type Policy

type Policy struct {
	MaxInputBytes  int64
	MaxPixels      int64
	MaxDimension   int
	MaxOutputBytes int64
}

Policy bounds source decoding and normalized model content.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy returns the common policy for current coding image sources.

type Prepared

type Prepared struct {
	Content        llm.ImageContent
	Bytes          int
	OriginalWidth  int
	OriginalHeight int
	OutputWidth    int
	OutputHeight   int
	Resized        bool
	Reencoded      bool
}

Prepared contains canonical model content and inspectable transformation facts. Raw bytes are represented only by Content.Data so metadata and logs do not accidentally duplicate the image payload.

func Prepare

func Prepare(ctx context.Context, input Input, policy Policy) (Prepared, error)

Prepare validates, fully decodes, bounds, and encodes one model image.

Jump to

Keyboard shortcuts

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