Layer
An object within a document that contains visual elements of the image, equivalent to a layer in Photoshop.
You can access layers in a document using Document.layers collection.
If the object is representing a group layer, you can access it's children layers using Layer.layers property.
Properties#
Name | Type | Access | Description |
---|---|---|---|
allLocked | boolean | Read-write | When set to true, prevents edits to pixels and properties of this layer |
blendMode | BlendMode | Read-write | The blend mode of the layer |
bounds | Bounds | Read-only | Bounds of the layer, including the effects |
boundsNoEffects | Bounds | Read-only | Bounds of the layer excluding effects |
document | Document | Read-only | The document this layer is in |
fillOpacity | number | Read-write | The fill opacity of the layer, in percentage. |
filterMaskDensity | number | Read-write | The density of the filter mask, in percentage. |
filterMaskFeather | number | Read-write | The feather of the filter mask between 0.0 and 1000.0. |
id | number | Read-only | ID of the layer, can be used for making batchPlay calls |
isBackgroundLayer | boolean | Read-only | - |
isClippingMask | boolean | Read-write | Is the mask used as a clipping mask. |
kind | LayerKind | Read-only | Kind of the layer |
layerMaskDensity | number | Read-write | The density of the layer mask, in percentage. |
layerMaskFeather | number | Read-write | The feather of the layer mask between 0.0 and 1000.0. |
layers | Layers | Read-only | The layers of this group layer ```javascript group.layers.forEach((layer) => { ... }) ``` |
linkedLayers | Layers | Read-only | Layers linked to this layer. See Layer.link |
locked | boolean | Read-only | True if any property of this layer is locked |
name | string | Read-only | Name of the layer |
opacity | number | Read-write | The master opacity of the layer, in percentage. |
parent | Layer | Read-only | The group layer this layer is in, null if the layer is a top layer in the document |
pixelsLocked | boolean | Read-write | When set to true, prevents the pixels of this layer from being edited |
positionLocked | boolean | Read-write | When set to true, prevents the layer from being moved |
transparentPixelsLocked | boolean | Read-write | When set to true, prevents the transparent pixels from being edited |
typename | string | Read-only | The class name of the referenced Layer object |
vectorMaskDensity | number | Read-write | The density of the vector mask, in percentage. |
vectorMaskFeather | number | Read-write | The feather of the vector mask between 0.0 and 1000.0 |
visible | boolean | Read-write | True when the layer is visible. |
Methods#
bringToFront#
void
Moves the layer to a position above the topmost layer or group.
clear#
async : Promise<void>
Clears the layer pixels and does not copy to the clipboard. If no pixel selection is found, select all pixels and clear.
copy#
async : Promise<void>
Copies the layer to the clipboard. When the optional argument is set to true, a merged copy is performed (that is, all visible layers are copied to the clipboard).
Copied to your clipboard1await layer.copy(true)2await layer.copy()
Parameters#
Name | Type |
---|---|
merge? | boolean |
cut#
async : Promise<void>
Cuts the layer to the clipboard. If no selection is found then select all the pixels and then cut.
delete#
void
Deletes this layer from the document.
Copied to your clipboard1const layers = document.layers2layers && layers[0] && layers[0].delete()
duplicate#
async : Promise<Layer>
Duplicates the layer, creating a copy above it in layer stack, and returns the newly created layer.
Copied to your clipboard1// duplicate a layer2const copyLayer = await layer.duplicate()34// extract to a new document5const exportDoc = psApp.documents[1]6const exportedLayer = await layer.duplicate(exportDoc)
Parameters#
Name | Type |
---|---|
relativeObject? | Document | Layer |
insertionLocation? | ElementPlacement |
name? | string |
flip#
async : Promise<void>
Flips the layer on one or both axis.
Copied to your clipboard1// flip horizontally2await layer.flip.horizontal()
Parameters#
Name | Type | Description |
---|---|---|
axis | "horizontal" | "vertical" | "both" | Which axis (or both) to flip the layer on. - "horizontal": flip layer on horizontal axis - "vertical": flip layer on vertical axis - "both": flip layer on both axes |
link#
Layer[]
Creates a link between this layer and the target layer if not already linked, and returns a list of layers linked to this layer.
Copied to your clipboard1// link two layers together2const linkedLayers = strokes.link(fillLayer)3linkedLayers.forEach((layer) => console.log(layer.name))4> "strokes"5> "fillLayer"
Parameters#
Name | Type |
---|---|
targetLayer | Layer |
merge#
async : Promise<Layer>
Merges layers. This operates on the currently selected layers. If multiple layers are selected, they will be merged together. If one layer is selected, it is merged down with the layer beneath. In this case, the layer below must be a pixel layer. The merged layer will now be the active layer.
move#
void
Moves the layer relative to the layer specified in parameters.
"placeAfter" places the layer below relativeObject.
"placeBefore" places the layer above relativeObject.
"placeInside" places the layer inside relativeObject if relativeObject is a group layer.
ElementPlacement.PLACEINSIDE
is only valid when relativeObject.kind === LayerKind.group
Parameters#
Name | Type |
---|---|
relativeObject | Layer |
insertLocation | ElementPlacement |
rasterize#
async : Promise<void>
Converts the targeted contents in the layer into a flat, raster image.
Parameters#
Name | Type |
---|---|
target | RasterizeType |
rotate#
async : Promise<void>
Rotates the layer.
Copied to your clipboard1// rotate 90 deg counter clockwise2await layer.rotate(-90)34// rotate 90 deg clockwise relative to top left corner5let anchorPos = require('photoshop').constants.AnchorPosition6await layer.rotate(90, anchorPos.TOPLEFT)
Parameters#
Name | Type | Description |
---|---|---|
angle | number | AngleValue | Angle to rotate the layer by in degrees |
anchor? | AnchorPosition | Anchor position to rotate around |
options? | object | - |
options.interpolation? | ResampleMethod | Interpolation method to use when resampling the image |
scale#
async : Promise<void>
Scales the layer.
Renamed from resize
in ExtendScript.
Copied to your clipboard1await layer.scale(80, 80)23// Scale the layer to be a quarter of the size relative to bottom left corner4let anchorPos = require('photoshop').constants.AnchorPosition5await layer.scale(50, 50, anchorPos.BOTTOMLEFT)
Parameters#
Name | Type | Description |
---|---|---|
width | number | PercentValue | Numeric percentage to scale layer horizontally |
height | number | PercentValue | Numeric percentage to scale layer vertically |
anchor? | AnchorPosition | Anchor position to rotate around |
options? | object | - |
options.interpolation? | ResampleMethod | Interpolation method to use when resampling the image |
sendToBack#
void
Moves the layer to the bottom. If the bottom layer is the background, it will move the layer to the position above the background. If it is in a group, it will move to the bottom of the group.
skew#
async : Promise<void>
Applies a skew to the layer.
Copied to your clipboard1// parellelogram shape2await layer.skew(-15, 0)
Parameters#
Name | Type | Description |
---|---|---|
angleH | number | AngleValue | Horizontal angle to skew by |
angleV | number | AngleValue | Vertical angle to skew by |
options? | object | - |
options.interpolation? | ResampleMethod | - |
translate#
async : Promise<void>
Moves the layer (translation).
Copied to your clipboard1// Translate the layer to the left by 200px2await layer.translate(-200, 0)34// move the layer one height down5let xOffsetPct = {_unit: "percentUnit", _value: 0};6let yOffsetPct = {_unit: "percentUnit", _value: 100};7await layer.translate(xOffsetPct, yOffsetPct);
Parameters#
Name | Type | Description |
---|---|---|
horizontal | number | PercentValue | PixelValue | Numeric value to offset layer by in pixels or percent |
vertical | number | PercentValue | PixelValue | Numeric value to offset layer by in pixels or percent |
unlink#
async : Promise<void>
Unlinks the layer from any existing links.
Copied to your clipboard1// detach layer from any existing links2await layer.unlink()