ColorSampler

Represents a ColorSampler object in the Photoshop DOM.

ColorSamplers are created through the ColorSamplers collection via the ColorSamplers.add method:

const app = require("photoshop").app;
app.activeDocument.colorSamplers.add({x: 100, y: 100});

Properties such as color, position and parent document can be then accessed on the ColorSampler instance:

let cs = app.activeDocument.colorSamplers[0];
console.log(cs.position);  // {x: 100, y: 100}
console.log(cs.color.rgb); // SolidColor {red: 0, green: 255, blue: 0}
console.log(cs.parent);    // Document

An existing ColorSampler instance can be moved to a different position:

cs.move({x: 200, y: 200});
console.log(cs.position);  // {x: 200, y: 200}

Or removed altogether from the document:

cs.remove();
console.log(app.activeDocument.colorSamplers.length); // 0

Properties

Name
Type
Access
Min Version
Description
color
SolidColor | NoColor
R
24.0
The color reading of this ColorSampler in its current position.
docId
number
R
24.0
The ID of the Document of this ColorSampler.
parent
Document
R
24.0
Owner document of this ColorSampler.
position
object
R
24.0
The position of this ColorSampler.
typename
string
R
24.0
The class name of the referenced object: "ColorSampler".

Methods

move

<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>

<br/> void

Moves the ColorSampler object to the given position

Parameters

Name
Type
Description
position
object
Object literal with target coordinates in pixels {x: number, y: number}.
position.x
number
-
position.y
number
-

remove

<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>

<br/> void

Deletes the given ColorSampler object.