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

Get selection area color

Engaged ,
Dec 26, 2021 Dec 26, 2021

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.   

TOPICS
Actions and scripting
483
Translate
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

correct answers 1 Correct answer

People's Champ , Dec 26, 2021 Dec 26, 2021
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);
Translate
Adobe
LEGEND ,
Dec 26, 2021 Dec 26, 2021

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

 

Translate
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
People's Champ ,
Dec 26, 2021 Dec 26, 2021
LATEST
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);
Translate
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