colorhelper
provides additional golang utilities for colors.
- sRGBA type compatible with the go
color.Color
andcolor.Model
interfaces. - HSLA type compatible with the go
color.Color
andcolor.Model
interfaces. - Function to parse representations of colors into
color.Color
values. - Function to generate representations of colors from
color.Color
values. - Function to choose the best text color for a given background color.
- Function to mix colors.
- Template function to tweak a CSS color value.
- Template function to to choose the best text color for a given background color.
c1, err := colorhelper.ParseCSSColorRepresentation("#FF0000")
if err != nil {
panic(err)
}
c2, err := colorhelper.ParseCSSColorRepresentation("hsla(0, 100%, 50%, 0.5)")
if err != nil {
panic(err)
}
fmt.Printf("%[1]T%[1]v\n", c1) // color.RGBA{255, 0, 0, 255}
fmt.Printf("%[1]T%[1]v\n", c2) // colorhelper.HSLA{0, 1, 0.5, 0.5}
c := color.RGBA{255, 0, 0, 127}
fmt.Println(colorhelper.MakeCSSColorRepresentation(c, colorhelper.HSLAFunctionRepresentation)) // hsla(0, 100%, 50%, 0.5)
fmt.Println(colorhelper.MakeCSSColorRepresentation(c, colorhelper.AnyRepresentation)) // rgba(255, 0, 0, 0.5)
{{ tweakcolor "#000000" "r" 255 }} => "#FF0000"
{{ tweakcolor "hsl(0, 100%, 0%)" "lightness" 0.5 }} => "hsl(0, 100%, 50%)"