image

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package image provides image optimization for GoSPA projects. Supports build-time optimization with optional on-the-fly processing.

Index

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 New

func New(cfg *Config) *ImagePlugin

New creates a new Image optimization plugin.

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.

func (*ImagePlugin) Init

func (p *ImagePlugin) Init() error

Init initializes the image plugin.

func (*ImagePlugin) Name

func (p *ImagePlugin) Name() string

Name returns the plugin name.

func (*ImagePlugin) OnHook

func (p *ImagePlugin) OnHook(hook plugin.Hook, ctx map[string]interface{}) error

OnHook handles lifecycle hooks.

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.

Jump to

Keyboard shortcuts

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