Edit in GitHubLog an issue

Solid Color

Represents a color, and allows for mapping into all available Photoshop color models. Import SolidColor from the Photoshop's app object:

Copied to your clipboard
const SolidColor = require("photoshop").app.SolidColor;

When a property is accessed (either via read or write), the current color model of the SolidColor objects gets set to the space of the accessor. Photoshop internally converts the color across these color spaces using the Color Settings set by the user.

For example, to set the foreground color to red:

Copied to your clipboard
1const SolidColor = require("photoshop").app.SolidColor;
2const red = new SolidColor();
3red.rgb.red = 255;
4red.rgb.green = 0;
5red.rgb.blue = 0;
6
7app.foregroundColor = red;

To understand how color models change as you interact with a SolidColor object, please see example below:

Copied to your clipboard
1const SolidColor = require("photoshop").app.SolidColor;
2const c = new SolidColor();
3console.log(c.base.typename); // By default, this will be "RGBColor"
4
5c.cmyk.cyan = 50; // Photoshop will convert the color to CMYK using Edit > Color Settings data
6console.log(c.base.typename); // Now, the typename will be "CMYKColor"
7
8c.rgb.green = 128; // Typename will change back to "RGBColor"
9

Fixes in Photoshop 24.2:

  • Adds range validation for all color modes and its components so it should not be possible to enter invalid value.

Constructors

constructor

23.0

SolidColor

All colors default to pure white.

Copied to your clipboard
1const SolidColor = require("photoshop").app.SolidColor;
2const color = new SolidColor();

Parameters

NameTypeDescription
model?
Color model to start.

Properties

NameTypeAccessMin VersionDescription
cmyk
R W
23.0
The color's representation in CMYK color space.
gray
R W
23.0
The color's representation in grayscale.
hsb
R W
23.0
The color's representation in HSB color space.
lab
R W
23.0
The color's representation in LAB color space.
nearestWebColor
R
23.0
The color's nearest match within the 216 web-safe colors.
rgb
R W
23.0
The color's representation in RGB color space.
typename
string
R
24.2
The class name of the referenced object: "SolidColor".

Methods

isEqual

23.0

boolean

True if the SolidColor object is visually equivalent to the specified color.

Both colors are converted to Lab colorspace, and the sum of their normalized squared Euclidian distance in each space is averaged across the three then compared to a small constant (3.5e-6).

Due to differences in coverage by various color spaces and clamping, a color that is converted from RGB to CMYK and back may not be visually equal.

Parameters

NameType
color
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.