image

package
v1.0.24 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 13 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 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.

Jump to

Keyboard shortcuts

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