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);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
If the input is a valid CSS color string in any format, including Oklch, it’s as easy as |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Ah, those strings seem to be just part of the Oklch color. The complete syntax uses the
oklch(...)
function.