Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

  • Print
  • + Share This
This chapter is from the book

Working with color objects

Your scripts can use the same range of colors that are available from the Adobe Photoshop CS2 user interface. Each color model has its own set of properties. For example, the RGB color class contains three properties: red, blue, and green. To set a color in this class, you indicate values for each of the three properties.

The SolidColor class contains a property for each color model. To use this object, you first create an instance of a SolidColor object, then set appropriate color model properties for the object. After a color model has been assigned to a SolidColor object, the SolidColor object cannot be reassigned to a different color model.

The following example demonstrates how to set a color using the CMYK color class.

//create a solid color array
var solidColorRef = new SolidColor()
solidColorRef.cmyk.cyan = 20
solidColorRef.cmyk.magenta = 90
solidColorRef.cmyk.yellow = 50 = 50

foregroundColor = solidColorRef

Solid color classes

The solid color classes available in Adobe Photoshop CS2 are illustrated below.

Using hex values

You can express RGB colors as hex (or hexadecimal) values. A hex value contains three pairs of numbers which represent red, blue, and green (in that order).

In JavaScript, the RGBColor object has a string property called HexValue/hexValue.

Getting and converting colors

The following example converts an RGB color to its CMYK equivalent. This example uses the foregroundColor property of the Application object to get the original color to be converted.

var someColor = foregroundColor.cmyk

Look up the following in Part 2 of this book:

  • cmyk in the Properties table of the SolidColor object
  • foregroundColor in the Properties table of the Application object

Comparing colors

Using the isEqual() method, you can compare colors. The following statement returns true if the foreground color is visually equal to background color.

if (app.foregroundColor.isEqual(backgroundColor))

Getting a web safe color

To convert a color to a web-safe color, use the nearestWebColor property of the SolidColor object.

var webSafeColor = new RGBColor()
webSafeColor = app.foregroundColor.nearestWebColor
  • + Share This
  • 🔖 Save To Your Account