Skip to content

Instantly share code, notes, and snippets.

@galdor
Last active March 18, 2023 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galdor/3844e62f299aaffa55a7dd48a7cf0911 to your computer and use it in GitHub Desktop.
Save galdor/3844e62f299aaffa55a7dd48a7cf0911 to your computer and use it in GitHub Desktop.
(defun g-hsl-to-rgb (string)
"Convert a HSL color string (e.g. \"hsl(200, 40%, 80%)\") to an
RGB color string (e.g. \"#e0b7b7\")."
(when (string-match
"^hsl( *\\([0-9]+\\) *, *\\([0-9]+\\)% *, *\\([0-9]+\\)% *)$" string)
(let* ((h (/ (string-to-number (match-string 1 string)) 360.0))
(s (/ (string-to-number (match-string 2 string)) 100.0))
(l (/ (string-to-number (match-string 3 string)) 100.0))
(rgb (color-hsl-to-rgb h s l))
(r (cl-first rgb))
(g (cl-second rgb))
(b (cl-third rgb)))
(color-rgb-to-hex r g b 2))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment