image

package
v1.3.127 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSize = 20 * 1024 * 1024

MaxSize is the maximum allowed image size (20MB).

Variables

View Source
var (
	MIMEJPEG = "image/jpeg"
	MIMEPNG  = "image/png"
	MIMEGIF  = "image/gif"
	MIMEWEBP = "image/webp"
)

Supported MIME types.

View Source
var ErrClipboardImageUnavailable = errors.New("clipboard does not contain an image")

Functions

func DataURI

func DataURI(img Image) string

DataURI returns a data URI for the image.

func DetectMIME

func DetectMIME(data []byte) string

DetectMIME detects image MIME type from magic bytes.

func EncodeBase64

func EncodeBase64(img Image) string

EncodeBase64 returns the base64-encoded representation of image data.

func IsImageFile

func IsImageFile(path string) bool

IsImageFile checks if a file path looks like an image based on extension.

func Placeholder

func Placeholder(filename string, img Image) string

Placeholder returns a TUI-friendly placeholder string for an image.

Types

type DisplayInfo added in v1.3.126

type DisplayInfo struct {
	Index     int    `json:"index"`
	IsPrimary bool   `json:"is_primary"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	X         int    `json:"x"`
	Y         int    `json:"y"`
	Name      string `json:"name,omitempty"`
}

DisplayInfo describes a monitor.

func ListDisplays added in v1.3.126

func ListDisplays() ([]DisplayInfo, error)

ListDisplays returns display information on Linux using xrandr or wlr-randr.

type Image

type Image struct {
	Data   []byte
	MIME   string // "image/png", "image/jpeg", etc.
	Width  int
	Height int
}

Image represents a decoded image ready for sending to providers.

func Decode

func Decode(data []byte) (Image, error)

Decode decodes raw image data, detecting MIME type and dimensions. Returns an error if data exceeds MaxSize or format is unsupported.

func ReadClipboard

func ReadClipboard() (Image, error)

func ReadFile

func ReadFile(path string) (Image, error)

ReadFile reads an image from a file path.

func ReadFromReader

func ReadFromReader(r io.Reader) (Image, error)

ReadFromReader reads an image from an io.Reader.

type ScreenshotAction added in v1.3.126

type ScreenshotAction string

ScreenshotAction specifies what the screenshot tool should do.

const (
	ActionCapture      ScreenshotAction = "capture"
	ActionListDisplays ScreenshotAction = "list_displays"
	ActionListWindows  ScreenshotAction = "list_windows"
)

type ScreenshotOptions added in v1.3.126

type ScreenshotOptions struct {
	Display    int               // 1-based monitor index, 0=primary
	Window     string            // match by title/app name
	Region     *ScreenshotRegion // rectangular area
	Cursor     bool              // include mouse cursor
	DelayMs    int               // delay before capture
	Format     string            // "png" or "jpeg"
	Quality    int               // JPEG quality 1-100
	OutputPath string            // save to file
	MaxWidth   int               // auto-resize max width
}

ScreenshotOptions controls screenshot capture behavior.

type ScreenshotRegion added in v1.3.126

type ScreenshotRegion struct {
	X, Y, Width, Height int
}

ScreenshotRegion defines a rectangular area to capture.

type ScreenshotResult added in v1.3.126

type ScreenshotResult struct {
	Image     Image
	SavedPath string
}

ScreenshotResult is the output of CaptureScreen.

func CaptureScreen added in v1.3.126

func CaptureScreen(opts ScreenshotOptions) (ScreenshotResult, error)

CaptureScreen captures a screenshot on Linux by auto-detecting an available screenshot tool.

type WindowInfo added in v1.3.126

type WindowInfo struct {
	ID     int    `json:"id"`
	Title  string `json:"title"`
	App    string `json:"app"`
	X      int    `json:"x"`
	Y      int    `json:"y"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

WindowInfo describes a capturable window.

func ListWindows added in v1.3.126

func ListWindows() ([]WindowInfo, error)

ListWindows returns capturable windows on Linux using wmctrl.

Jump to

Keyboard shortcuts

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