How to convert oklch to hex #246
|
Hello, I stumbled across this library while working on a project of mine. I'm working to extract daisyui colors, which are in oklch format and use them in my canvas system. I'm struggling getting the conversion to work and would love ideas on how to do this better. This library looks like it should be the right answer to this kind of situation function oklchToHex(oklchStr: string): string {
const [l, c, h] = oklchStr
.split(",")
.map((val) => val.replace("%", ""))
.map(Number);
const color = oklch({ mode: "oklch", l: l / 100, c, h });
return formatHex(color);
} |
Answered by
danburzo
Oct 28, 2024
Replies: 2 comments 2 replies
|
If the input is a valid CSS color string in any format, including Oklch, it’s as easy as |
0 replies
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Ah, those strings seem to be just part of the Oklch color. The complete syntax uses the
oklch(...)function.