Documentation ¶
Index ¶
- Constants
- func CompressionName(tags Tags) string
- func CompressionQuality(tags Tags) int
- func DimensionName(tags Tags) string
- type Compression
- type CompressionFunc
- type Compressor
- type CompressorOption
- type DimensionList
- type DimensionMap
- type DimensionProvider
- type Dimensions
- type JSONDimensions
- type Pipeline
- type PipelineResult
- type Processed
- type Processor
- type ProcessorContext
- type ProcessorFunc
- type Resizer
- type ResizerOption
- type Tagger
- type Tags
Constants ¶
const ( // Compressed is the tag that is assigned to compressed images. Compressed = "compressed" // AnonymousCompression is the name [Compression.Name] of a CompressionFunc. AnonymousCompression = "anonymous" )
const Original = "original"
Original is the tag that is assigned to the original image that is passed to Pipeline.Run.
const Resized = "resized"
Resized is the tag that is assigned to resized images.
Variables ¶
This section is empty.
Functions ¶
func CompressionName ¶
CompressionName extracts the name of the Compression from the tags of a processed image.
func CompressionQuality ¶
CompressionQuality extracts the name of the compression quality from the tags of a processed image. If the tags to not provide the compression quality, -1 is returned.
func DimensionName ¶
DimensionName extracts the dimension name from the tags of a processed image.
Types ¶
type Compression ¶
type Compression interface { // Compress compresses an image. Compress(img image.Image) (image.Image, error) }
Compression provides the actual implementation for compressing images.
type CompressionFunc ¶
CompressionFunc allow a function to be used as a Compression.
type Compressor ¶
type Compressor struct {
// contains filtered or unexported fields
}
Compressor compresses images.
func Compress ¶
func Compress(compression Compression, opts ...CompressorOption) *Compressor
Compress returns a *Compressor that compresses images using the provided Compression. If the provided Compression has a `Tags() Tags` method, the returned *Compressor will append these tags to compressed images when calling *Compressor.Process.
func CompressMany ¶
func CompressMany(compressions []Compression, opts ...CompressorOption) *Compressor
CompressMany returns a *Compressor that compresses images using the provided [Compression]s. If a provided Compression method has a `Tags() Tags` method, the returned *Compressor will append these tags to compressed image when calling *Compressor.Process.
func (*Compressor) Process ¶
func (c *Compressor) Process(ctx ProcessorContext) ([]Processed, error)
Process implements Processor. By default, the original image will not be compressed and returned as is to preserve quality. To also compress the original image, pass the CompressOriginal option to Compress.
type CompressorOption ¶
type CompressorOption func(*Compressor)
CompressorOption is an option for a *Compressor.
func CompressOriginal ¶
func CompressOriginal(v bool) CompressorOption
CompressOriginal returns a CompressorOption that enables compression of the original image of a Pipeline. By default, the original image will not be compressed and instead returned as is to preserve the original image quality.
type DimensionList ¶
type DimensionList []Dimensions
DimensionList is a list of Dimensions.
func (DimensionList) Dimensions ¶
func (dl DimensionList) Dimensions() []Dimensions
Dimensions returns the dimension list.
type DimensionMap ¶
type DimensionMap map[string]Dimensions
DimensionMap provides named Dimensions.
func (DimensionMap) Dimensions ¶
func (dm DimensionMap) Dimensions() []Dimensions
Dimensions returns the dimension list.
func (DimensionMap) Tag ¶
func (dm DimensionMap) Tag(dim Dimensions) string
Tag returns the configured tag for the given Dimensions.
type DimensionProvider ¶
type DimensionProvider interface {
Dimensions() []Dimensions
}
DimensionProvider provides image dimensions to Resizer. DimensionProvider is implemented by DimensionList and DimensionMap.
type Dimensions ¶
type Dimensions [2]int
Dimensions are the width and height of an image, in pixels.
func (Dimensions) JSON ¶ added in v0.0.3
func (d Dimensions) JSON() JSONDimensions
func (Dimensions) MarshalJSON ¶ added in v0.0.2
func (d Dimensions) MarshalJSON() ([]byte, error)
func (Dimensions) String ¶
func (d Dimensions) String() string
func (*Dimensions) UnmarshalJSON ¶ added in v0.0.3
func (d *Dimensions) UnmarshalJSON(data []byte) error
type JSONDimensions ¶ added in v0.0.3
type Pipeline ¶
type Pipeline []Processor
Pipeline is a list of Processors that are applied to an image.
func (Pipeline) Run ¶
Run runs the pipeline on an image and returns the PipelineResult, containing the processed images.
type PipelineResult ¶
type PipelineResult struct { // Images are the processed images. Images []Processed // Input is the original image that was passed to the [Pipeline]. Input image.Image }
PipelineResult is the result of running a Pipeline on an image.
func (PipelineResult) Find ¶
func (result PipelineResult) Find(tags ...string) []Processed
Find returns the processed images that have at least 1 of the given tags. If no tags are provided, nil is returned.
func (PipelineResult) Match ¶
func (result PipelineResult) Match(re *regexp.Regexp) []Processed
Match returns the processed images that have at least 1 tag that matches the given regular expression.
func (PipelineResult) Original ¶
func (result PipelineResult) Original() (Processed, bool)
Original returns the processed image that is tagged as the original image. Depending on the Pipeline, the original image may have been transformed by one or more [Processor]s. [PipelineResult.Input] is the actual image that was passed to Pipeline.Run.
If the Pipeline discarded the original image from its result, false is returned.
type Processed ¶
Processed is a processed image, except if the Original field is set to true. In that case, it is the original image that was passed to Pipeline.Run.
type Processor ¶
type Processor interface {
Process(ProcessorContext) ([]Processed, error)
}
A Processor processes an image and returns possibly multiple processed images.
type ProcessorContext ¶
type ProcessorContext interface { context.Context // Image is the input image for the Processor. Image() Processed }
ProcessorContext is passed to Processors.
func NewProcessorContext ¶
func NewProcessorContext(ctx context.Context, img Processed) ProcessorContext
NewProcessorContext returns a new ProcessorContext for a Processor.
type ProcessorFunc ¶
type ProcessorFunc func(ProcessorContext) ([]Processed, error)
ProcessorFunc allows functions to be used a Processors.
type Resizer ¶
type Resizer struct {
// contains filtered or unexported fields
}
Resizer resizes images to a set of dimensions.
func Resize ¶
func Resize(dimensions DimensionProvider, opts ...ResizerOption) *Resizer
Resize returns a Resizer that resizes images to the given dimensions.
type ResizerOption ¶
type ResizerOption func(*Resizer)
ResizerOption is an option for a Resizer.
func DiscardInput ¶
func DiscardInput(v bool) ResizerOption
DiscardInput returns a ResizerOption that discards the input image from the resize result when executed in a Pipeline.
func ResampleFilter ¶
func ResampleFilter(filter imaging.ResampleFilter) ResizerOption
ResampleFilter returns a ResizerOption that sets the imaging.ResampleFilter to use when resizing images. Defaults to imaging.Lanczos.
type Tagger ¶
type Tagger struct {
// contains filtered or unexported fields
}
Tagger is a Processor that adds tags to images.
type Tags ¶
type Tags []string
Tags is a list of tags that Processors assigned to images in a Pipeline.