Copy link to clipboard
Copied
I would like the color selected by color sample
be put in the foreground window.
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
app.foregroundColor = myDocument.colorSamplers[0].color
};
Copy link to clipboard
Copied
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
app.foregroundColor = myDocument.colorSamplers[0].color
};
Copy link to clipboard
Copied
It works perfectly
because you wrote it use it at your own risk?
sorry if you take advantage of your help
and if I wanted to pick the color of a selection
be put in the foreground window.
Copy link to clipboard
Copied
because you wrote it use it at your own risk?
I just like to make sure that I make no guarantees about Scripts I post.
and if I wanted to pick the color of a selection
be put in the foreground window.
What do you mean exactly? A Selection may cover any number of pixels of different colors, do you mean the average?
Maybe posting a screenshot or mock-up might help me understand what you are trying to achieve.
Copy link to clipboard
Copied
A selection can cover any number of pixels of different colors, do you mean the average?
I meant the average.
Copy link to clipboard
Copied
You have to test whether this gives you the intended results:
// set foregtound color to selection average;
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.mode == DocumentMode.RGB) {
var theR = histogramMean (myDocument.channels[0].histogram);
var theG = histogramMean (myDocument.channels[1].histogram);
var theB = histogramMean (myDocument.channels[2].histogram);
// make forground color;
var theColor = new SolidColor();
theColor.rgb.red = theR;
theColor.rgb.green = theG;
theColor.rgb.blue = theB;
app.foregroundColor = theColor;
};
};
//////
function histogramMean (histo) {
var mean = 0;
var total = 0;
for (var n = 0; n < histo.length; n++) {
total = total + histo
};
for (var m = 0; m < histo.length; m++) {
var thisValue = histo
mean = mean + (m * thisValue / total);
};
return mean
};
Copy link to clipboard
Copied
Perfect
Copy link to clipboard
Copied
The code would only work for RGB images, if you need to precess others (CMYK, Grayscale …) you need to adapt it accordingly.
Copy link to clipboard
Copied
thanks for your time.