Copy link to clipboard
Copied
When the open photoshop document has an active selection, can a photoshop script detect if the selection area contains more than one color?
The objective is to apply an action to the selection area when it contains a single color only.
For example if the selection area contains #FFFFFF, #000000 or #265499 apply an action to the area.
var x = 0;
var ch = app.activeDocument.channels;
for (var i = 0; i < 3 & x <= 3; i++)
{
var hist = ch[i].histogram;
for (var n = 0; n < 256 & x <= 3; n++)
{
if (hist[n]) ++x;
}
}
var single = x==3;
alert(single);
Copy link to clipboard
Copied
1) use Window / Mesurement Log to export and read Gray Value (mean).
2) then read it and use Color Range to select the only one color.
3) repeat item one and compare results (to undo history state).
Or if you care of shades of colours then use:
chnnls = [].slice.call(activeDocument.channels); while(chnnls.length) {
if(String(chnnls.shift().histogram).split(/[1-9]\d*/).join('').length<510)break
}
!chnnls.length
Copy link to clipboard
Copied
var x = 0;
var ch = app.activeDocument.channels;
for (var i = 0; i < 3 & x <= 3; i++)
{
var hist = ch[i].histogram;
for (var n = 0; n < 256 & x <= 3; n++)
{
if (hist[n]) ++x;
}
}
var single = x==3;
alert(single);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now