images

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter func(*ProcessingContext) error

Filter is a function that modifies the ProcessingContext.

func FormatWebp

func FormatWebp() Filter

FormatWebp converts the output format to WebP.

func Resize

func Resize(width, height uint) Filter

Resize resizes the image to the specified width and height. If one of width or height is 0, it preserves aspect ratio if the underlying library supports it (nfnt/resize does).

func ResizeAspectRatio

func ResizeAspectRatio(width, height uint, keepRatio bool) Filter

ResizeAspectRatio resizes the image to fit within the specified width and height while maintaining aspect ratio. If keepRatio is false, it forces the dimensions to exact width and height. If keepRatio is true, it scales the image such that it fits within width x height, preserving the original aspect ratio.

func ValidateRatio

func ValidateRatio(ratio string) Filter

ValidateRatio validates if the image aspect ratio matches the expected ratio. Supported ratios: "1:1", "16:9", "9:16".

type ImageProcessor

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

ImageProcessor handles the image processing pipeline.

func NewImageProcessor

func NewImageProcessor() *ImageProcessor

NewImageProcessor creates a new instance of ImageProcessor.

func (*ImageProcessor) AddFilter

func (p *ImageProcessor) AddFilter(filters ...Filter) *ImageProcessor

AddFilter adds filters to the processing pipeline and returns a new ImageProcessor instance. It does not modify the current instance.

func (*ImageProcessor) Process

func (p *ImageProcessor) Process(input io.Reader) (io.Reader, error)

Process processes the input image through the filter chain and returns the result.

type ProcessingContext

type ProcessingContext struct {
	Image        image.Image
	OutputFormat string // "jpeg", "png", "webp", etc.
	Quality      int    // Quality for jpeg/webp (0-100). Default usually 75-90 depending on encoder.
}

ProcessingContext holds the state of the image during processing.

Jump to

Keyboard shortcuts

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