Documentation
¶
Overview ¶
Package image provides utilities for loading and processing images.
Index ¶
- func ExpandTilde(path string) string
- func ResolveImagePath(path string) (string, error)
- func ScanDirectoryForImages(dirPath string) ([]string, error)
- func SelectRandomImage(imagePaths []string) (string, error)
- func SupportedImageExtensions() []string
- func ValidateImagePath(path string) error
- type FileLoader
- type Loader
- type SmartLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandTilde ¶ added in v0.1.22
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 ¶
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 ¶
ScanDirectoryForImages scans a directory and returns all valid image files. It does not recurse into subdirectories, but follows symlinks.
func SelectRandomImage ¶
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 ¶
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.
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.