-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatermark_options.go
73 lines (59 loc) · 1.64 KB
/
watermark_options.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
package image
import (
"github.com/webx-top/echo/param"
)
type WMType string
const (
WM_TYPE_TEXT WMType = `text`
WM_TYPE_IMAGE WMType = `image`
)
func NewWatermarkOptions() *WatermarkOptions {
return &WatermarkOptions{}
}
// WatermarkOptions 水印选项
type WatermarkOptions struct {
Watermark string `json:"watermark"` // 水印图片文件路径
Type WMType `json:"type,omitempty"` // 水印类型
Position Pos `json:"position"` // 水印的位置
Padding int `json:"padding"` // 水印留的边白
On bool `json:"on"` // 是否开启水印
}
func (w *WatermarkOptions) FromStore(r param.Store) *WatermarkOptions {
w.On = r.Bool(`on`)
w.Padding = r.Int(`padding`)
w.Position = Pos(r.Int(`position`))
w.Type = WMType(r.String(`type`))
w.Watermark = r.String(`watermark`)
return w
}
func (w *WatermarkOptions) SetWatermark(watermark string, typ WMType) *WatermarkOptions {
w.Watermark = watermark
w.Type = typ
return w
}
func (w *WatermarkOptions) SetPosition(position Pos) *WatermarkOptions {
w.Position = position
return w
}
func (w *WatermarkOptions) SetPadding(padding int) *WatermarkOptions {
w.Padding = padding
return w
}
func (w *WatermarkOptions) Enable() *WatermarkOptions {
w.On = true
return w
}
func (w *WatermarkOptions) IsEnabled() bool {
return w.On && len(w.Watermark) > 0
}
func (w *WatermarkOptions) Disable() *WatermarkOptions {
w.On = false
return w
}
func (w *WatermarkOptions) SetOn(on bool) *WatermarkOptions {
w.On = on
return w
}
func (w *WatermarkOptions) CreateInstance() (*Watermark, error) {
return NewWatermark(w.Watermark, w.Padding, w.Position)
}