colorconv

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 6 Imported by: 23

README

colorconv

Go Reference Go Report Card

Library to support RGB conversion to HSL, HSV and Hex value for Golang. This library make use of Go standard library with no external dependency.

INSTALLATION / UPDATING
go get -u github.com/crazy3lf/colorconv

Documentation

Overview

Package colorconv provide conversion of color to HSL, HSV and hex value. All the conversion methods is based on the website: https://www.rapidtables.com/convert/color/index.html

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHexValue = errors.New("colorconv: invalid input")
View Source
var ErrOutOfRange = errors.New("colorconv: inputs out of range")

Functions

func ColorToHSL

func ColorToHSL(c color.Color) (h, s, l float64)

ColorToHSL convert color.Color into HSL triple, ignoring the alpha channel.

func ColorToHSV

func ColorToHSV(c color.Color) (h, s, v float64)

ColorToHSV convert color.Color into HSV triple, ignoring the alpha channel.

func ColorToHex

func ColorToHex(c color.Color) string

ColorToHex convert color.Color into Hex string, ignoring the alpha channel.

func HSLToColor added in v1.1.0

func HSLToColor(h, s, l float64) (color.Color, error)

HSLToColor convert HSL triple into color.Color.

func HSLToRGB

func HSLToRGB(h, s, l float64) (r, g, b uint8, err error)

HSLToRGB converts an HSL triple to an RGB triple.

func HSVToColor added in v1.1.0

func HSVToColor(h, s, v float64) (color.Color, error)

HSVToColor convert HSV triple into color.Color.

func HSVToRGB

func HSVToRGB(h, s, v float64) (r, g, b uint8, err error)

HSVToRGB converts an HSV triple to an RGB triple.

func HexToColor added in v1.1.0

func HexToColor(hex string) (color.Color, error)

HexToColor convert Hex string into color.Color.

func HexToRGB

func HexToRGB(hex string) (r, g, b uint8, err error)

HexToRGB converts a Hex string to an RGB triple.

func RGBToGrayAverage added in v1.2.0

func RGBToGrayAverage(r, g, b uint8) color.Gray

RGBToGrayAverage calculates the grayscale value of RGB with the average method, ignoring the alpha channel.

func RGBToGrayWithWeight added in v1.2.0

func RGBToGrayWithWeight(r, g, b uint8, rWeight, gWeight, bWeight uint) color.Gray

RGBToGrayWithWeight calculates the grayscale value of RGB wih provided weight, ignoring the alpha channel. In the standard library image/color, the conversion used the coefficient given by the JFIF specification. It is equivalent to using the weight 299, 587, 114 for rgb.

func RGBToHSL

func RGBToHSL(r, g, b uint8) (h, s, l float64)

RGBToHSL converts an RGB triple to an HSL triple.

func RGBToHSV

func RGBToHSV(r, g, b uint8) (h, s, v float64)

RGBToHSV converts an RGB triple to an HSV triple.

func RGBToHex

func RGBToHex(r, g, b uint8) string

RGBToHex converts an RGB triple to a Hex string in the format of 0xffff.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL