-
Notifications
You must be signed in to change notification settings - Fork 31
/
rgb.go
40 lines (30 loc) · 752 Bytes
/
rgb.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
package processors
import (
"fmt"
"github.com/lucasb-eyer/go-colorful"
)
// HexToRGB convert hex color code to R, G, B codes
// here we are using data library helper.
type HexToRGB struct{}
func (p HexToRGB) Name() string {
return "hex-rgb"
}
func (p HexToRGB) Alias() []string {
return nil
}
func (p HexToRGB) Transform(data []byte, _ ...Flag) (string, error) {
c, err := colorful.Hex(string(data))
return fmt.Sprintf("%d, %d, %d", int(c.R*255), int(c.G*255), int(c.B*255)), err
}
func (p HexToRGB) Flags() []Flag {
return nil
}
func (p HexToRGB) Title() string {
return "Hex To RGB"
}
func (p HexToRGB) Description() string {
return "Convert a #hex-color code to RGB"
}
func (p HexToRGB) FilterValue() string {
return p.Title()
}