https://github.com/troublete/go-colors
Color conversion and distance calculation
https://github.com/troublete/go-colors
Last synced: 3 months ago
JSON representation
Color conversion and distance calculation
- Host: GitHub
- URL: https://github.com/troublete/go-colors
- Owner: troublete
- License: mit
- Created: 2024-10-18T17:03:24.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-10-21T08:43:07.000Z (7 months ago)
- Last Synced: 2025-01-03T16:33:27.764Z (5 months ago)
- Language: Go
- Size: 1.62 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-colors
> color calculations and conversions for every-day use[](https://pkg.go.dev/github.com/troublete/go-colors/colors)
## Introduction
This provides some 'every-day' color calculation and conversions that allows easier color discovery, matching and
handling.* convert HEX to sRGB
* convert sRGB to HEX
* convert sRGB to XYZ
* convert sRGB to HSL
* convert XYZ to L*a*b*
* calculate distance (delta E) between two L*a*b* colors
* calculate WCAG contrast ratio between to sRGB colors**Example**
```go
a := NewRGB(120, 120, 12).ToXYZ().ToLAB()
b := NewRGB(230, 123, 40).ToXYZ().ToLAB()deltaE := a.DistanceTo(b)
```
## CLI### match-colors
This CLI accepts two CSV files (a 'source' collection of available colors; a 'match' which contains the colors you try
to match) – with format: collection(string),name(string),lrv(float64),r(float64),g(float64),b(
float64) – which then are compared concurrently and outputs the top 10 closest colors in respect to the match CSV
file.**Example**
```bash
$ go run ./cmd/match -match my-colors.csv -source colors_available.csv -no-header -filter *available_name_filter_regex*
```### delta-e
This CLI accepts two HEX color codes and returns the delta E value of both colors.
### hex-to-rgb
This CLI accepts a HEX color code and returns a ready-to-use RGB snippet for CSS.
### rgb-to-hsl
This CLI accepts three parameters (R, G, B) and convert them to a ready-to-use HSL snippet for CSS.
### rgb-to-hex
This CLI accepts three parameters (R, G, B) and converts them to a ready-to-use HEX color code.
### wcag-contrast-check
This CLI accepts two HEX color codes and returns the WCAG contrast ratio + if it succeeds the required 7:1 ratio.