-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.go
158 lines (139 loc) · 2.13 KB
/
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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package goarion
import (
"errors"
"strings"
)
type ImageType int
// These must be kept in sync with the defines in arion/carion.h
const (
JPEG ImageType = iota
PNG
JP2
WEBP
AVIF
)
type Gravity int
const (
CENTER Gravity = iota
NORTH
SOUTH
WEST
EAST
NORTH_WEST
NORTH_EAST
SOUTH_WEST
SOUTH_EAST
)
type Algo int
const (
WIDTH Algo = iota
HEIGHT
SQUARE
FILL
)
type WatermarkType int
const (
STANDARD WatermarkType = iota
ADAPTIVE
)
func (wt *WatermarkType) UnmarshalText(b []byte) error {
str := strings.Trim(string(b), `"`)
switch str {
case "STANDARD":
*wt = STANDARD
case "ADAPTIVE":
*wt = ADAPTIVE
default:
return errors.New("Unknown WatermarkType: " + string(b))
}
return nil
}
func (wt WatermarkType) String() string {
switch wt {
case STANDARD:
return "STANDARD"
case ADAPTIVE:
return "ADAPTIVE"
default:
return "UNKNOWN"
}
}
type Options struct {
ImageType ImageType
Width int
Height int
Algo Algo
Gravity Gravity
Quality int
SharpenRadius float64
SharpenAmount int
WatermarkURL string
WatermarkType WatermarkType
WatermarkAmount float64
WatermarkMin float64
WatermarkMax float64
}
func AlgoToString(a Algo) string {
switch a {
case WIDTH:
return "width"
case HEIGHT:
return "height"
case SQUARE:
return "square"
case FILL:
return "fill"
default:
return "invalid"
}
}
func StringToAlgo(s string) Algo {
switch s {
case "width":
return WIDTH
case "height":
return HEIGHT
case "square":
return SQUARE
default:
return FILL
}
}
func GravtiyToString(g Gravity) string {
switch g {
case NORTH:
return "n"
case SOUTH:
return "s"
case WEST:
return "w"
case EAST:
return "e"
case NORTH_WEST:
return "nw"
case NORTH_EAST:
return "ne"
case SOUTH_WEST:
return "sw"
case SOUTH_EAST:
return "se"
default:
return "c"
}
}
func WatermarkTypeToString(w WatermarkType) string {
switch w {
case ADAPTIVE:
return "adaptive"
default:
return "standard"
}
}
func StringToWatermarkType(s string) WatermarkType {
switch s {
case "adaptive":
return ADAPTIVE
default:
return STANDARD
}
}