forked from cshum/imagor
/
option.go
142 lines (125 loc) · 2.76 KB
/
option.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package vips
import (
"go.uber.org/zap"
"strings"
)
// Option Processor option
type Option func(v *Processor)
// WithFilter with filer option of name and FilterFunc pair
func WithFilter(name string, filter FilterFunc) Option {
return func(v *Processor) {
v.Filters[name] = filter
}
}
// WithDisableBlur with disable blur option
func WithDisableBlur(disabled bool) Option {
return func(v *Processor) {
v.DisableBlur = disabled
}
}
// WithDisableFilters with disable filters option
func WithDisableFilters(filters ...string) Option {
return func(v *Processor) {
for _, raw := range filters {
splits := strings.Split(raw, ",")
for _, name := range splits {
name = strings.TrimSpace(name)
if len(name) > 0 {
v.DisableFilters = append(v.DisableFilters, name)
}
}
}
}
}
// WithMozJPEG with MozJPEG option. Require MozJPEG to be installed
func WithMozJPEG(enabled bool) Option {
return func(v *Processor) {
v.MozJPEG = enabled
}
}
// WithMaxFilterOps with maximum number of filter operations option
func WithMaxFilterOps(num int) Option {
return func(v *Processor) {
if num != 0 {
v.MaxFilterOps = num
}
}
}
// WithMaxAnimationFrames with maximum count of animation frames option
func WithMaxAnimationFrames(num int) Option {
return func(v *Processor) {
if num != 0 {
v.MaxAnimationFrames = num
}
}
}
// WithConcurrency with libvips concurrency option
func WithConcurrency(num int) Option {
return func(v *Processor) {
if num != 0 {
v.Concurrency = num
}
}
}
// WithMaxCacheFiles with libvips max cache files option
func WithMaxCacheFiles(num int) Option {
return func(v *Processor) {
if num > 0 {
v.MaxCacheFiles = num
}
}
}
// WithMaxCacheSize with libvips max cache size option
func WithMaxCacheSize(num int) Option {
return func(v *Processor) {
if num > 0 {
v.MaxCacheSize = num
}
}
}
// WithMaxCacheMem with libvips max cache mem option
func WithMaxCacheMem(num int) Option {
return func(v *Processor) {
if num > 0 {
v.MaxCacheMem = num
}
}
}
// WithLogger with logger option
func WithLogger(logger *zap.Logger) Option {
return func(v *Processor) {
if logger != nil {
v.Logger = logger
}
}
}
// WithDebug with debug option
func WithDebug(debug bool) Option {
return func(v *Processor) {
v.Debug = debug
}
}
// WithMaxWidth with maximum width option
func WithMaxWidth(width int) Option {
return func(v *Processor) {
if width > 0 {
v.MaxWidth = width
}
}
}
// WithMaxHeight with maximum height option
func WithMaxHeight(height int) Option {
return func(v *Processor) {
if height > 0 {
v.MaxHeight = height
}
}
}
// WithMaxResolution with maximum resolution option
func WithMaxResolution(res int) Option {
return func(v *Processor) {
if res > 0 {
v.MaxResolution = res
}
}
}