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

How to check if swatch is a light color

Community Beginner ,
Jul 12, 2019 Jul 12, 2019

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!

TOPICS
Scripting

Views

611

Translate

Translate

Report

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
Adobe
Guru ,
Jul 14, 2019 Jul 14, 2019

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 

Votes

Translate

Translate

Report

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
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

LATEST

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;

  }

  }

  }

Votes

Translate

Translate

Report

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