Skip to main content
Participating Frequently
March 1, 2017
Question

Detect colors and alpha in document/layers

  • March 1, 2017
  • 1 reply
  • 1117 views

Hi everyone,

I'm trying to make a script that make a folder with each layers (normal and solidfill) as images and get text in text layers and put informations about layers in a JSON files. It is to use it after in a zip file to make something behind.
The thing is, I'm having some problems.

First, I duplicate and crop layer by layer with bounds informations to make the image.
The problem is, I would like to know if there is some pixels with alpha so I save it as a PNG, if no transparency, then I save it as a JPG.
Info : i put opacity to 100, so it's not about opacity, but pixels which was not filled;

Then, it happends that my layer is just one rectangle with one color
I don't know how to know if the layer is fully fill, and only one color
Cause this kind of layer must not be save as an image, I'll just take informations in a JSON that this layer is a one color rectangle.


So that's my 2 problems
• Detect alpha/transparency (not opacity) in a layer/document
• Detect if I have a layer fully fill with only one color

Thanks everyone

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
March 1, 2017

1) You could use the AM code for loading the Layer’s transparency and then evaluate the Selection’s histogram in QuickMask mode.

2) You could evaluate the Layer’s histogram.

MoukyAuthor
Participating Frequently
March 1, 2017

Thank you for your reply

1) AM code ?
sorry, I'm a neophyte in Adobe Script, and I don't know much more about english tools name

2) Yeah, I did that to know if I have only one color, but still, I don't know which color it is

c.pfaffenbichler
Community Expert
Community Expert
March 1, 2017

1) Action Manger code – you can record that with ScriptingListener.plugin – as opposed to Document Object Model code (DOM) which looks »cleaner« but is usually less efficient.

2) If each Channel’s histogram has only on non-zero number the index of that number would indicate the value.