Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Register ¶
func Register(factory FilterFactory)
Register registers a filter with it's FilterFactory which is used to create instances of the corresponding filter.
Types ¶
type Filter ¶
type Filter interface {
// Apply applies the image filter to an image and returns the new image.
Apply(*caddy.Replacer, image.Image) (image.Image, error)
}
Filter is a image filter that can be applied to an image.
type FilterFactory ¶
type FilterFactory interface {
// Name returns the name of the filter, which is also the directive used in the image filter
// block. It should be in lower case.
Name() string
// New initialises and returns the image filter instance.
New(...string) (Filter, error)
// Unmarshal decodes JSON configuration and returns the corresponding image filter instance.
Unmarshal([]byte) (Filter, error)
}
FilterFactory generates instances of it's corresponding image filter.
type ImageFilter ¶
type ImageFilter struct {
// The file system implementation to use. By default, Caddy uses the local disk file system.
FileSystemRaw json.RawMessage `json:"file_system,omitempty" caddy:"namespace=caddy.fs inline_key=backend"`
// Filters is a map of initialized image filters. Keys have the form
// "<position>_<image filter name>", where <position> specifies the order in which the image
// filters will be applied.
Filters filters `json:"filters,omitempty"`
// Root is the path to the root of the site. Default is `{http.vars.root}` if set, or current
// working directory otherwise.
Root string `json:"root,omitempty"`
// FilterOrder is a slice of strings in the form "<position>_<image filter name>". Each entry
// should have a corresponding entry in the Filters map.
FilterOrder []string `json:"filter_order,omitempty"`
// JpegQuality determines the quality of jpeg encoding after the filters are applied. It ranges
// from 1 to 100 inclusive, higher is better. Default is 75.
JpegQuality int `json:"jpeg_quality,omitempty"`
// PngCompression determines the compression of png images. Possible values are:
// * 0: Default compression
// * -1: no compression
// * -2: fastest compression
// * -3: best compression
PngCompression int `json:"png_compression,omitempty"`
// MaxConcurrent determines how many request can be served concurrently. Default is 0, which
// means unlimited
MaxConcurrent int64 `json:"max_concurrent,omitempty"`
// contains filtered or unexported fields
}
ImageFilter is a caddy module that can apply image filters to images from the filesystem at runtime. It should be used together with a cache module, so filters don't have to be applied repeatedly because it's an expensive operation.
func (ImageFilter) CaddyModule ¶
func (ImageFilter) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*ImageFilter) Provision ¶
func (img *ImageFilter) Provision(ctx caddy.Context) error
Provision sets up image filter module.
func (*ImageFilter) ServeHTTP ¶
func (img *ImageFilter) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP looks for the file in the current root directory and applys the configured filters.
func (*ImageFilter) Validate ¶
func (img *ImageFilter) Validate() error
Validate validates the configuration of the image filter module.
Source Files
¶
- imagefilter.go