• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Detect colors and alpha in document/layers

Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

847

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

I have no knowledge in Action Manager Code and ScriptingListener.plugin, but I will try to do some research

For histogram, I have a full square, color is : ff0032, RGB is 255, 0, 50
but on histogram, it gives me 0 and 204330

how convert 204330 to rgb or hexa code ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

Hexa code is best to be disregarded in my opinion.

Which histogram are you talking about? The composite or the three channels’?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

histogram is from
app.document.histogram

I need hexadecimal value for web
it's a kind of PSD to webpage script (not really it, but a step to it)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

I need hexadecimal value for web

How are RGB-values (sRGB naturally) less meaningful?

histogram is from

app.document.histogram

You need to evaluate all three (if the image is RGB) channels’ histograms.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

Hexadecimal or RGB, it's just that 204330 means nothing to me

I will try with channel histogram, see if I have something

EDIT : arf, cannot take the Channel histogram

Photoshop CC Javascript Documentation :
Channel.histogram

Not valid when kind = ChannelType.COMPONENT. For component channel histogram values, use the histogram property of the Document object instead.

and all my ChannelType are COMPONENT, so I cannot access this

and Document.histogram only gives me an array of number =/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

You talk about a Script, but you don’t Post the code …

Have you used something like

var histo1= activeDocument.channels[0].histogram;

var histo2= activeDocument.channels[1].histogram;

var histo3= activeDocument.channels[2].histogram;

?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

Script is in Javascript

Can't share all the code, because it's for the company

The thing is, when I do

var colors = activeDocument.histogram.getUnique();
alert(colors);

It always gives me 0 and another number (for square with one color)

getUnique() => Array method I made to have unique values in array

activeDocument.channels.histogram always gives me the same result
for my exemple with a red square (ff0032), it always gives me [0, 204330]

the thing is, in my PSD exemple, I also have a grey square (copy of the red square, and change color, it's a polyfiil layer), and it also sends [0, 204330]...  u_u

Plus, when I go in "Export for the web" inside the Photoshop Application, there is a colors table with all color used in the document, and I don't know how to do the same, or to get it.

Same goes for pixel not fill (transparent pixel)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

var colors = activeDocument.histogram.getUnique();

getUnique? I think that is not part of the JavaScript version used for Adobe Scripting.

And once again: the Channels’ histogram, not the document’s!

If you do not want to show the pertinent section of the code you are talking about I see little point in this thread …

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

Now my last problem is the transparent pixel areas

How can I tell to my script if there is some

Just find out !

For exemple, if my square element is RGB(255, 0, 33)
in channel Red, I will have 256 values, all "0" except the last one (256th)
in channel Blue, all 0 except the first position
in channel Green, all 0 except the 34th position

so RGB = position (start at 0 for the first) of the number in each channel

Now my problem is for the transparent pixels area
If there is at least one transparent pixel in the layer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

Just find out !

For exemple, if my square element is RGB(255, 0, 33)
in channel Red, I will have 256 values, all "0" except the last one (256th)
in channel Blue, all 0 except the first position
in channel Green, all 0 except the 34th position

Is that a question or a description?

Now my problem is for the transparent pixels area

If there is at least one transparent pixel in the layer

Once again: Use the AM code to load the Layer’s transparency, switch to QuickMask mode and evaluate that Channel’s histogram.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2017 Mar 01, 2017

Copy link to clipboard

Copied

LATEST

It was a description
So one problem solved

Now I need to understand the AM code and things, and it will be good

Thanks to you for helping me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines