kip
Color (github) is a comprehensive color library. Now at version 0.2 but much more developed than the long ago 0.1. In fact I expect to move this to 1.0 release quite quickly since I consider its API stable. Feedback might change that though! ![]()
Features
-
20+ color space structs including
Color.SRGB,Color.AdobeRGB,Color.RGB(linear, in any of 24 named working spaces),Color.Lab,Color.LCHab,Color.Luv,Color.LCHuv,Color.XYZ,Color.XYY,Color.Oklab,Color.Oklch,Color.HSLuv,Color.HPLuv,Color.Hsl,Color.Hsv,Color.CMYK,Color.YCbCr,Color.JzAzBz,Color.ICtCp,Color.IPT,Color.CAM16UCS. -
Top-level conversion API.
Color.new/2andColor.convert/2,3,4accept structs, hex strings, CSS named colors, atoms, or bare lists of numbers (with strict per-space validation) and convert between any pair of supported spaces.Color.convert_many/2,3,4is the batch equivalent. Alpha is preserved across every path. -
Chromatic adaptation with six methods (
:bradford,:xyz_scaling,:von_kries,:sharp,:cmccat2000,:cat02).Color.convert/3,4auto-adapts the source illuminant when the target requires a fixed reference white. -
ICC rendering intents wired into
Color.convert/3,4::relative_colorimetric(default),:absolute_colorimetric,:perceptual,:saturation. Optional black-point compensation viabpc: true. -
ICC matrix-profile reader (
Color.ICC.Profile) for ICC v2 / v4 RGB→XYZ profiles, withcurvLUT andparaparametric tone response curves. Loads profiles likesRGB IEC61966-2.1.icc,Display P3.icc,AdobeRGB1998.icc, and most camera and scanner profiles. -
Color difference (ΔE). CIE76, CIE94, CIEDE2000 (verified against the Sharma 2005 test data), and CMC l:c.
-
Contrast. WCAG 2.x relative luminance and contrast ratio, APCA W3 0.1.9 (
L_c), andpick_contrasting/2for accessibility helpers. -
Mixing and gradients.
Color.Mix.mix/4interpolates in any supported space (default Oklab) with CSS Color 4 hue-interpolation modes (:shorter,:longer,:increasing,:decreasing).Color.Mix.gradient/4produces evenly spaced gradients. -
Gamut checking and mapping.
Color.Gamut.in_gamut?/2andColor.Gamut.to_gamut/3with the CSS Color 4 Oklch binary-search algorithm or simple RGB clip. -
Color harmonies. Complementary, analogous, triadic, tetradic, and split-complementary in any cylindrical space (default Oklch).
-
Color temperature. CCT ↔ chromaticity, Planckian locus and CIE daylight locus.
-
CSS Color Module Level 4 / 5. Full parser and serialiser for hex, named colors,
rgb()/rgba(),hsl()/hsla(),hwb(),lab(),lch(),oklab(),oklch(),color(srgb|display-p3|rec2020|…),device-cmyk(),color-mix(), relative color syntax,nonekeyword, andcalc()expressions. -
~COLORsigil for compile-time color literals in any supported space. -
Spectral pipeline.
Color.SpectralandColor.Spectral.Tablesprovide the CIE 1931 2° and CIE 1964 10° standard observer CMFs, the D65 / D50 / A / E illuminant SPDs, emissive and reflective integration to XYZ, and a metamerism helper. -
Blend modes. All 16 CSS Compositing Level 1 modes (
:multiply,:screen,:overlay,:darken,:lighten,:color_dodge,:color_burn,:hard_light,:soft_light,:difference,:exclusion,:hue,:saturation,:color,:luminosity,:normal). -
Transfer functions. sRGB, gamma 2.2 / 1.8, L*, BT.709, BT.2020, PQ (SMPTE ST 2084), HLG, Adobe RGB γ.
A proper Color module has been largely the last sticking point before I could consider moving image to version 1.0. With this update to color I will soon be able to move image to 1.0 too.
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mudasobwa
Splendid!
Do you think
Color.ANSI(terminal escape sequences) might belong to this library, alongside withColor.CSSor it’s out of scope?kip
Oooooo.I like that idea. Something like
Color.to_ansi/1you mean? Parsing the sequences too?mudasobwa
Yes. Both parsing and producing. I recently published
Marcliwhich is essentially a markdown parser for terminals and I would love to use more sophisticated coloring there.kip
Consider it done for the next release. Maybe even today.
mudasobwa
Thank you!
And yes, I’ll never get tired of repeating it, your work on Elixir ecosystem is astonishing, thank you for that.
kip
I published Color v0.3.0 with the following additions:
Color.ANSImodule for parsing and emitting ANSI SGR colour escape sequences. Supports 16-colour, 256-colour indexed, and 24-bit truecolor forms, with perceptual nearest-palette matching (CIEDE2000) when encoding to the 16- or 256-colour palette. Includesparse/1,to_string/2,wrap/3,nearest_256/1,nearest_16/1,palette_256/0,palette_16/0, and a typedColor.ANSI.ParseErrorexception.Top-level
Color.to_hex/1,Color.to_css/1,2, andColor.to_ansi/1,2convenience functions that accept any inputColor.new/1accepts and raise a typed exception on failure.And yes, AI can definitely assist in cases like this where the domain is clear, the specification is clear and the expected results are clear.
mudasobwa
They say, Socrates once argued that Understanding a question is half an answer. Literally nothing has changed with ages.
a-maze-d
One more thing you might want to consider adding: extra meta-info to colors.
This is maybe special to my use case, but when you try to address an LED strip, you can not only specify an RGB tripplet, but also one or even 2 white LEDs. It would be nice if those could be specified as part of a color.
I know that this a rather special use case and can cause quite a few headaches, but I thought it might still be worth considering.
kip
You can already specify and illuminate (typically d50 or d65) on a conversion. Can you point me at a reference I can study - happy to look at adding color metadata.
lud
So cool!
Is there a way so safely convert oklch to a displayable srgb color?