I know this question has been asked here already but there hasn’t been any answer that make sense and the developer is a nightmare to get hold of.
Using PSD.js the colours for text characters don’t match RGB, RGBA or CMYK, there are 5 numbers in the a colour arrays, they don’t even match the text colour in the Photoshop file if you try to compare any of the numbers to the RBG or CMYK values.
An example what PSD.js is showing for colours of a particular part of text shows this array:
[3] => Array
(
[0] => 27
[1] => 185
[2] => 116
[3] => 0
[4] => 255
)
You can clearly see these have no relevance to any colour codes I have seen before. These numbers are supposedly representing this colour: #db6971 – but none of the numbers match anything, the RGB for that is 219,105,113 and CMYK is 11%,72%,46%,0%
So does anyone have a clue what is going on here? I am trying to render this text to html but I can’t set the colour without actually knowing what these numbers are supposed to mean.
2
Answers
As explained in the post on the official GitHub page of PSD.js repo – https://github.com/meltingice/psd.js/issues/119#issuecomment-346899211
…to transform the array you could do something like this.
If you multiply your CMYK percentages with 255 (the max value of a byte), you get pretty close to the values you see in your array (28, 184, 117, 0). The last value is probably the alpha (transparency) component, 255 meaning all opaque. So, I’d say this is CMYK+A
Given your array:
If you need the CMYK value in percentages, it’s just an equation you need to solve.
Ie. for the C value in percent, it’s
which gives you
etc.
Which is pretty close to the CMYK (11%, 72%, 46%, 0%) you expected.
Now, if you want the values in RGB, CMYK to RGB conversion is best done using ICC profiles (from one specific input CMYK input profile to a specific RGB output, like sRGB).
You can also use one of the simplified algorithms you find on the web. It will work, just don’t expect it to look like the conversion done by Photoshop.