meltingice / psd.js

A Photoshop PSD file parser for NodeJS and browsers
MIT License
2.75k stars 391 forks source link

Extracting RGB(A) from single color layers ? #71

Open fabulousduck opened 8 years ago

fabulousduck commented 8 years ago

Is it possible to get the color from layers that are 1 single color ? I've found the solidColor() function but those RGB values are always 0 and it would be awfully tedious making an image out of it first and then getting the color from that. Is there any way of getting the RGB(A) or HEX values from a layer ?

Kind regards : Ryan Vlaming

joliejuke-orga commented 7 years ago

Hi, unfortunately, you can only extract color from a shape layer by doing the following:

node.get('solidColor').data  

----------
> output:
{ class: { name: '', id: 'null' },
  'Clr ':
   { class: { name: '', id: 'RGBC' },
     'Rd  ': 122.30150654911995,
     'Grn ': 204.45926159620285,
     'Bl  ': 199.90488678216934 } }

In the case of smart objects or pixelised layers you can't extract that property. You can use modules like this one: https://www.npmjs.com/package/get-image-colors But as you said, it's really tedious.

fabulousduck commented 7 years ago

This is something that should probably be integrated in the vanilla rewrite. What do you think @meltingice ?