Skip to main content
Participating Frequently
October 15, 2012
Question

finding out brightness of color

  • October 15, 2012
  • 1 reply
  • 743 views

Is it possible to find out how bright is an color? I need to find the darkest color in document's swatches. My solution would be to convert (script internally, without actually making any changes in document) swatches to grayscale, compare them and pick the darkest. But how to convert  swatch defined in undefined mode (they might be in lab or cmyk) to grayscale?

I found in 'js scriping reference' a method "convertSampleColor", but I have no idea how to use it. Any examples?

This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
October 15, 2012

here's a usage sample, it converts from rgb to lab

var c = new RGBColor();

c.red = 255;

c.green = 255;

c.blue = 0;

var newColor = app.convertSampleColor (ImageColorSpace.RGB, [c.red,c.green,c.blue], ImageColorSpace.LAB,ColorConvertPurpose.previewpurpose);

alert(newColor);

Participating Frequently
October 15, 2012

It works. But it took me a while to figure out, that grayscale should be written as GrayScale

var c = new RGBColor();
c.red = 255;
c.green = 255;
c.blue = 0;
var newColor = app.convertSampleColor (ImageColorSpace.RGB, [c.red,c.green,c.blue], ImageColorSpace.GrayScale,ColorConvertPurpose.previewpurpose);
alert(newColor);