image

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package image provides utilities for loading and processing images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandTilde added in v0.1.22

func ExpandTilde(path string) string

ExpandTilde expands a tilde prefix in a path to the user's home directory. Returns the original path unchanged if it doesn't start with ~ or if home directory lookup fails.

func ResolveImagePath

func ResolveImagePath(path string) (string, error)

ResolveImagePath resolves a path that could be a file or directory. If the path is a directory, it scans for images and returns a random one. If the path is a file, it returns the path as-is. For HTTP(S) URLs, it returns the URL as-is. Tilde paths (~/...) are expanded to the user's home directory.

func ScanDirectoryForImages

func ScanDirectoryForImages(dirPath string) ([]string, error)

ScanDirectoryForImages scans a directory and returns all valid image files. It does not recurse into subdirectories, but follows symlinks.

func SelectRandomImage

func SelectRandomImage(imagePaths []string) (string, error)

SelectRandomImage selects a random image from a list of image paths. Uses crypto/rand for cryptographically secure randomness.

func SupportedImageExtensions

func SupportedImageExtensions() []string

SupportedImageExtensions returns a list of supported image file extensions.

func ValidateImagePath

func ValidateImagePath(path string) error

ValidateImagePath checks if the given path is valid and points to a supported image file or directory. Supports both local file paths, directories, and HTTP(S) URLs. For local files, it verifies the file exists and can be decoded. For directories, it verifies the directory exists (actual scanning happens later). For HTTP(S) URLs, it just validates the URL format (actual fetching happens later). Tilde paths (~/...) are expanded to the user's home directory.

Types

type FileLoader

type FileLoader struct{}

FileLoader loads images from the local filesystem.

func NewFileLoader

func NewFileLoader() *FileLoader

NewFileLoader creates a new FileLoader instance.

func (*FileLoader) Load

func (l *FileLoader) Load(path string) (image.Image, error)

Load loads an image from a file path. Supported formats: JPEG, PNG, GIF, WebP.

type Loader

type Loader interface {
	// Load loads an image from the given path.
	Load(path string) (image.Image, error)
}

Loader handles loading images from various sources.

type SmartLoader

type SmartLoader struct {
	// contains filtered or unexported fields
}

SmartLoader loads images from both local files and HTTP(S) URLs.

func NewSmartLoader

func NewSmartLoader() *SmartLoader

NewSmartLoader creates a new SmartLoader instance.

func (*SmartLoader) Load

func (l *SmartLoader) Load(path string) (image.Image, error)

Load loads an image from either a local file path or HTTP(S) URL.

Jump to

Keyboard shortcuts

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