-
Notifications
You must be signed in to change notification settings - Fork 1
/
grayscale.go
52 lines (43 loc) · 1.19 KB
/
grayscale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package grayscale
import (
"image"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/disintegration/imaging"
imagefilter "github.com/ueffel/caddy-imagefilter/v2"
)
// Grayscale produces a grayscaled version of the image.
type Grayscale struct{}
// UnmarshalCaddyfile configures the Grayscale instance.
//
// Syntax:
//
// grayscale
//
// no parameters.
func (*Grayscale) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
if d.CountRemainingArgs() > 0 {
return imagefilter.ErrTooManyArgs
}
return nil
}
// Apply applies the image filter to an image and returns the new image.
func (f *Grayscale) Apply(repl *caddy.Replacer, img image.Image) (image.Image, error) {
return imaging.Grayscale(img), nil
}
// CaddyModule returns the Caddy module information.
func (Grayscale) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "http.handlers.image_filter.filter.grayscale",
New: func() caddy.Module { return new(Grayscale) },
}
}
// init registers the image filter.
func init() {
caddy.RegisterModule(Grayscale{})
}
// Interface guards.
var (
_ imagefilter.Filter = (*Grayscale)(nil)
_ caddyfile.Unmarshaler = (*Grayscale)(nil)
)