forked from h2non/imaginary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
64 lines (59 loc) · 1.45 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
package main
import "gopkg.in/h2non/bimg.v1"
// ImageOptions represent all the supported image transformation params as first level members
type ImageOptions struct {
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
Opacity float32
Text string
Font string
Type string
Color []uint8
Extend bimg.Extend
Gravity bimg.Gravity
Colorspace bimg.Interpretation
Background []uint8
}
// 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,
Type: ImageType(o.Type),
Rotate: bimg.Angle(o.Rotate),
}
if len(o.Background) != 0 {
opts.Background = bimg.Color{o.Background[0], o.Background[1], o.Background[2]}
}
return opts
}