imagefilter

package module
v0.0.0-...-f45a019 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 22 Imported by: 0

README

caddy-imagefilter

根据 caddy-imagefilter 魔改,增加了水印功能

安装

xcaddy build --with github.com/hakutyou/caddy-imagefilter/watermark

使用

{
    order image_filter before file_server
}

your-web.site {
    root * /path/to/website

    file_server

    # 所有的图片
    @thumbnail {
        path_regexp thumb /.+\.(jpg|jpeg|png|gif|bmp|tif|tiff|webp)$
    }

    image_filter @thumbnail {
        # 只支持 png 图片
        watermark /path/to/image.png
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooFewArgs  = errors.New("too few arguments")
	ErrTooManyArgs = errors.New("too many arguments")
)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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