Package color provides color manipulation and format conversion.
-
Get package:
go get -u github.com/gowww/color
-
Import it in your code:
import "github.com/gowww/color"
To get a Color instance from an hexadecimal representation, use NewHex:
color.NewHex("#004bff")
To get a Color instance from red, green and blue values, use NewRGB:
color.NewRGB(0, 75, 255)
To get a Color instance from red, green, blue and alpha values, use NewRGBA:
color.NewRGBA(0, 75, 255, .5)
To get the hexadecimal representation of a Color without alpha, use Color.Hex:
color.NewRGBA(0, 75, 255, .5).Hex() // "#004bff"
To get the hexadecimal representation of a Color with alpha, use Color.HexAlpha or Color.AlphaHex:
color.NewRGBA(0, 75, 255, .5).HexAlpha() // "#004bff7f"
color.NewRGBA(0, 75, 255, .5).HexAlpha() // "#7f004bff"