I'm parsing a PSD getting normal RGBA values and recently I encountered this strange float color values:
{
"red": 1.0343483686447144,
"green": 0.9487225413322449,
"blue": -0.12634865939617157,
"alpha": 100,
"rgba": "rgba(1.0343483686447144, 0.9487225413322449, -0.12634865939617157, 1)"
}
Here is my parsing function:
function getRGBColor(color, opacity = 100) {
if ("Clr " in color) {
color = color["Clr "];
}
var type = color.class.id;
var red = color["Rd "];
var green = color["Grn "];
var blue = color["Bl "];
if ("blueFloat" in color) {
red = color.redFloat;
green = color.greenFloat;
blue = color.blueFloat;
}
var rgba = {
red: red,
green: green,
blue: blue,
alpha: opacity,
rgba: `rgba(${red}, ${green}, ${blue}, ${opacity/100})`
}
return rgba;
}
It's supposed to be yellow.
The object is coming from strokeColorContent
.
var vectorMask = node.get("vectorMask")?.export();
var vectorStroke = node.get("vectorStroke")?.data;
var vectorStrokeContent = node.get("vectorStrokeContent")?.data;
var fillColor = getRGBColor(vectorStrokeContent);
Related question:
How to convert PSD vector path to SVG path data
Update:
I've updated the CSS to use the lab()
color space as suggested and it seems to work:
lab(94 -12 103)
I haven't confirmed the alpha value yet but this seems to work:
lab(94 -12 103 / 1)
It seems that, in most browsers, lab()
is being supported (not currently in Firefox but in Firefox 113).
To get the rgba() value there needs to be a formula from lab to rgba.