Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Created May 12, 2022 13:51
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 daviddarnes/46f32fcfd57e0395e9e06bd3f978a313 to your computer and use it in GitHub Desktop.
Save daviddarnes/46f32fcfd57e0395e9e06bd3f978a313 to your computer and use it in GitHub Desktop.
Function to turn hex colour values into p3 color values
const hexToP3 = (string) => {
var aRgbHex = string.replace("#", "").match(/.{1,2}/g);
var aRgb = [
(parseInt(aRgbHex[0], 16) / 255).toFixed(2),
(parseInt(aRgbHex[1], 16) / 255).toFixed(2),
(parseInt(aRgbHex[2], 16) / 255).toFixed(2),
];
return `color(display-p3 ${aRgb.join(" ")})`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment