Documentation
¶
Overview ¶
Package image provides image optimization for GoSPA projects. Supports build-time optimization with optional on-the-fly processing.
Index ¶
- type Config
- type FormatConfig
- type ImagePlugin
- func (p *ImagePlugin) Commands() []plugin.Command
- func (p *ImagePlugin) Dependencies() []plugin.Dependency
- func (p *ImagePlugin) GetConfig() *Config
- func (p *ImagePlugin) Init() error
- func (p *ImagePlugin) Name() string
- func (p *ImagePlugin) OnHook(hook plugin.Hook, ctx map[string]interface{}) error
- type SizeConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// SourceDir is where source images are located.
SourceDir string `yaml:"source_dir" json:"sourceDir"`
// OutputDir is where optimized images are written.
OutputDir string `yaml:"output_dir" json:"outputDir"`
// Quality is the compression quality (1-100).
Quality int `yaml:"quality" json:"quality"`
// Formats to convert to.
Formats FormatConfig `yaml:"formats" json:"formats"`
// Sizes for responsive images.
Sizes []SizeConfig `yaml:"sizes" json:"sizes"`
// OnTheFly enables runtime image optimization.
OnTheFly bool `yaml:"on_the_fly" json:"onTheFly"`
// OnTheFlyCacheDir is the cache directory for on-the-fly images.
OnTheFlyCacheDir string `yaml:"on_the_fly_cache_dir" json:"onTheFlyCacheDir"`
// PreserveOriginals keeps original files alongside optimized versions.
PreserveOriginals bool `yaml:"preserve_originals" json:"preserveOriginals"`
// LazyLoadThreshold sets the threshold for lazy loading (in bytes).
LazyLoadThreshold int64 `yaml:"lazy_load_threshold" json:"lazyLoadThreshold"`
// MaxImageSize is the maximum allowed image file size in bytes (default: 20MB).
MaxImageSize int64 `yaml:"max_image_size" json:"maxImageSize"`
// MaxDimensions is the maximum allowed width/height in pixels (default: 8192).
MaxDimensions int `yaml:"max_dimensions" json:"maxDimensions"`
// Concurrency is the number of parallel workers (default: runtime.GOMAXPROCS).
Concurrency int `yaml:"concurrency" json:"concurrency"`
}
Config holds image optimization configuration.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default image optimization configuration.
type FormatConfig ¶
type FormatConfig struct {
// WebP enables WebP conversion.
WebP bool `yaml:"webp" json:"webP"`
// AVIF enables AVIF conversion.
AVIF bool `yaml:"avif" json:"avif"`
// JPEG enables JPEG optimization.
JPEG bool `yaml:"jpeg" json:"jpeg"`
// PNG enables PNG optimization.
PNG bool `yaml:"png" json:"png"`
}
FormatConfig configures output formats.
type ImagePlugin ¶
type ImagePlugin struct {
// contains filtered or unexported fields
}
ImagePlugin provides image optimization capabilities.
func (*ImagePlugin) Commands ¶
func (p *ImagePlugin) Commands() []plugin.Command
Commands returns custom CLI commands.
func (*ImagePlugin) Dependencies ¶
func (p *ImagePlugin) Dependencies() []plugin.Dependency
Dependencies returns required dependencies.
func (*ImagePlugin) GetConfig ¶
func (p *ImagePlugin) GetConfig() *Config
GetConfig returns the current configuration.
type SizeConfig ¶
type SizeConfig struct {
// Name is the size identifier (e.g., "thumbnail", "medium", "large").
Name string `yaml:"name" json:"name"`
// Width is the target width in pixels.
Width int `yaml:"width" json:"width"`
// Height is the target height in pixels (0 for auto).
Height int `yaml:"height" json:"height"`
// Quality override for this size (0 uses default).
Quality int `yaml:"quality" json:"quality"`
}
SizeConfig defines a responsive image size.
Click to show internal directories.
Click to hide internal directories.