Skip to content

Color conversion and distance calculation

License

Notifications You must be signed in to change notification settings

troublete/go-colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-colors

color calculations and conversions for every-day use

Go Reference

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 Lab*
  • calculate distance (delta E) between two Lab* colors
  • calculate WCAG contrast ratio between to sRGB colors

Example

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

$ 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.

About

Color conversion and distance calculation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages