-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
105 lines (95 loc) · 2.68 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
package main
import "gopkg.in/h2non/bimg.v1"
// ImageOptions represent all the supported image transformation params as first level members
type ImageOptions struct {
IsDefinedField
Width int
Height int
AreaWidth int
AreaHeight int
Quality int
Compression int
Rotate int
Top int
Left int
Margin int
Factor int
DPI int
TextWidth int
Flip bool
Flop bool
Force bool
Embed bool
NoCrop bool
NoReplicate bool
NoRotation bool
NoProfile bool
StripMetadata bool
Opacity float32
Sigma float64
MinAmpl float64
Text string
Image string
Font string
Type string
Color []uint8
Background []uint8
Extend bimg.Extend
Gravity bimg.Gravity
Colorspace bimg.Interpretation
Operations PipelineOperations
}
// IsDefinedField holds boolean ImageOptions fields. If true it means the field was specified in the request. This
// metadata allows for sane usage of default (false) values.
type IsDefinedField struct {
Flip bool
Flop bool
Force bool
Embed bool
NoCrop bool
NoReplicate bool
NoRotation bool
NoProfile bool
StripMetadata bool
}
// PipelineOperation represents the structure for an operation field.
type PipelineOperation struct {
Name string `json:"operation"`
IgnoreFailure bool `json:"ignore_failure"`
Params map[string]interface{} `json:"params"`
ImageOptions ImageOptions `json:"-"`
Operation Operation `json:"-"`
}
// PipelineOperations defines the expected interface for a list of operations.
type PipelineOperations []PipelineOperation
// BimgOptions creates a new bimg compatible options struct mapping the fields properly
func BimgOptions(o ImageOptions) bimg.Options {
opts := bimg.Options{
Width: o.Width,
Height: o.Height,
Flip: o.Flip,
Flop: o.Flop,
Quality: o.Quality,
Compression: o.Compression,
NoAutoRotate: o.NoRotation,
NoProfile: o.NoProfile,
Force: o.Force,
Gravity: o.Gravity,
Embed: o.Embed,
Extend: o.Extend,
Interpretation: o.Colorspace,
StripMetadata: o.StripMetadata,
Type: ImageType(o.Type),
Rotate: bimg.Angle(o.Rotate),
}
if len(o.Background) != 0 {
opts.Background = bimg.Color{R: o.Background[0], G: o.Background[1], B: o.Background[2]}
}
if o.Sigma > 0 || o.MinAmpl > 0 {
opts.GaussianBlur = bimg.GaussianBlur{
Sigma: o.Sigma,
MinAmpl: o.MinAmpl,
}
}
return opts
}