Adobe 23101335 Scripting Guide - Page 79

Comparing Colors, 3.14.4 Getting a Web Safe Color

Page 79 highlights

Scripting Photoshop 3 Color objects The examples below show how to convert the foreground color to a Lab color. AS: -- Convert foreground application color to Lab set myLabColor to convert color foreground color to Lab VB: ' Get the foreground color as Lab Dim myLabColor As Photoshop.LabColor Set myLabColor = appRef.ForegroundColor.Lab JS: // Get the Lab color from the foreground color. var myLabColor = foregroundColor.lab; 3.14.3 Comparing Colors Using the equal colors (IsEqual/isEqual) commands, you can easily compare colors. These methods will return true if the colors are visually equal to each other and false otherwise. The examples below compare the foreground color to the background color. AS: if equal colors foreground color with background color then VB: If (appRef.ForegroundColor.IsEqual(appRef.BackgroundColor)) Then JS: if (foregroundColor.isEqual(backgroundColor)) 3.14.4 Getting a Web Safe Color To convert a color to a web safe color use the web safe color command on AppleScript and the NearestWebColor/nearestWebColor property on the SolidColor object for Visual Basic and JavaScript. The web safe color returned is an RGB color. AS: set myWebSafeColor to web safe color for foreground color VB: Dim myWebSafeColor As Photoshop.RGBColor Set myWebSafeColor = appRef.ForegroundColor.NearestWebColor JS: var webSafeColor = new RGBColor(); webSafeColor = foregroundColor.nearestWebColor; Photoshop 7.0 Scripting Guide 79

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91

Photoshop 7.0 Scripting Guide
79
Scripting Photoshop
Color objects
3
The examples below show how to convert the foreground color to a Lab color.
AS:
-- Convert foreground application color to Lab
set myLabColor to convert color foreground color to Lab
VB:
' Get the foreground color as Lab
Dim myLabColor As Photoshop.LabColor
Set myLabColor = appRef.ForegroundColor.Lab
JS:
// Get the Lab color from the foreground color.
var myLabColor = foregroundColor.lab;
3.14.3 Comparing Colors
Using the
equal colors (IsEqual/isEqual)
commands, you can easily compare
colors. These methods will return
true
if the colors are visually equal to each other and
false
otherwise. The examples below compare the foreground color to the background color.
AS:
if equal colors foreground color with background color then
VB:
If (appRef.ForegroundColor.IsEqual(appRef.BackgroundColor)) Then
JS:
if (foregroundColor.isEqual(backgroundColor))
3.14.4 Getting a Web Safe Color
To convert a color to a web safe color use the
web safe color
command on AppleScript
and the
NearestWebColor/nearestWebColor
property on the
SolidColor
object for
Visual Basic and JavaScript. The web safe color returned is an RGB color.
AS:
set myWebSafeColor to web safe color for foreground color
VB:
Dim myWebSafeColor As Photoshop.RGBColor
Set myWebSafeColor = appRef.ForegroundColor.NearestWebColor
JS:
var webSafeColor = new RGBColor();
webSafeColor = foregroundColor.nearestWebColor;