Converting RGB to grayscale/intensity

The specific numbers in the question are from CCIR 601 (see Wikipedia article). If you convert RGB -> grayscale with slightly different numbers / different methods, you won’t see much difference at all on a normal computer screen under normal lighting conditions — try it. Here are some more links on color in general: Wikipedia … Read more

RGB values of visible spectrum

I recently found out that my spectral colors don’t work properly because they were based on nonlinear and shifted data. So I did little research and data compilation and found out that most spectrum images out there are incorrect. Also, the color ranges do not match to each other, so I used from this point … Read more

HSL to RGB color conversion

Garry Tan posted a Javascript solution on his blog (which he attributes to a now defunct mjijackson.com, but is archived here and the original author has a gist – thanks to user2441511). The code is re-posted below: HSL to RGB: /** * Converts an HSL color value to RGB. Conversion formula * adapted from http://en.wikipedia.org/wiki/HSL_color_space. … Read more

How to get hex color value rather than RGB value?

TLDR Use this clean one-line function with both rgb and rgba support: const rgba2hex = (rgba) => `#${rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)$/).slice(1).map((n, i) => (i === 3 ? Math.round(parseFloat(n) * 255) : parseFloat(n)).toString(16).padStart(2, ‘0’).replace(‘NaN’, ”)).join(”)}` 2021 updated answer Much time has passed since I originally answered this question. Then cool ECMAScript 5 and 2015+ features become largely available on … Read more