Copy link to clipboard
Copied
I have a script that creates a legend of colors used in a file, but sometimes I have colors that are light and can't be seen against a white background, how can I know when a swatch is light.
Thanks!
Copy link to clipboard
Copied
There's lot's of mathematical ways of doing it. I wrote a script that orders swatches as per luminance one can use simplifications of the various delta formulas and compare them with white.
The simplest DOM method would be to use app.convertSampleColor and convert to grayscale. Then decide what gray scale you consider gray.
For the Logo Package Express extension I developed I used a math method for the inverted color scheme which changes dark colors to white.
See these for some screenshots.
Logo Package Express Extension – Creative-Scripts.com
Package Logo Files for Clients in Under 5 Minutes | The Logo Package
Copy link to clipboard
Copied
I found the solution in one of John Wundes scripts.
Here is the function:
function is_dark(c) {
if (c.typename) {
switch (c.typename) {
case "CMYKColor":
return (c.black > 20 || (c.cyan > 20 && c.magenta > 20)) ? true : false;
case "RGBColor":
return (c.red < 50 && c.green < 50) ? true : false;
case "GrayColor":
return c.gray > 20 ? true : false;
case "SpotColor":
return is_dark(c.spot.color);
return false;
}
}
}