Edit in GitHubLog an issue

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#

NameTypeAccessDescription
allLockedbooleanRead-writeWhen set to true, prevents edits to pixels and properties of this layer
blendModeBlendModeRead-writeThe blend mode of the layer
boundsBoundsRead-onlyBounds of the layer, including the effects
boundsNoEffectsBoundsRead-onlyBounds of the layer excluding effects
documentDocumentRead-onlyThe document this layer is in
fillOpacitynumberRead-writeThe fill opacity of the layer, in percentage.
filterMaskDensitynumberRead-writeThe density of the filter mask, in percentage.
filterMaskFeathernumberRead-writeThe feather of the filter mask between 0.0 and 1000.0.
idnumberRead-onlyID of the layer, can be used for making batchPlay calls
isBackgroundLayerbooleanRead-only-
isClippingMaskbooleanRead-writeIs the mask used as a clipping mask.
kindLayerKindRead-onlyKind of the layer
layerMaskDensitynumberRead-writeThe density of the layer mask, in percentage.
layerMaskFeathernumberRead-writeThe feather of the layer mask between 0.0 and 1000.0.
layersLayersRead-onlyThe layers of this group layer ```javascript group.layers.forEach((layer) => { ... }) ```
linkedLayersLayersRead-onlyLayers linked to this layer. See Layer.link
lockedbooleanRead-onlyTrue if any property of this layer is locked
namestringRead-onlyName of the layer
opacitynumberRead-writeThe master opacity of the layer, in percentage.
parentLayerRead-onlyThe group layer this layer is in, null if the layer is a top layer in the document
pixelsLockedbooleanRead-writeWhen set to true, prevents the pixels of this layer from being edited
positionLockedbooleanRead-writeWhen set to true, prevents the layer from being moved
transparentPixelsLockedbooleanRead-writeWhen set to true, prevents the transparent pixels from being edited
typenamestringRead-onlyThe class name of the referenced Layer object
vectorMaskDensitynumberRead-writeThe density of the vector mask, in percentage.
vectorMaskFeathernumberRead-writeThe feather of the vector mask between 0.0 and 1000.0
visiblebooleanRead-writeTrue 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 clipboard
1await layer.copy(true)
2await layer.copy()

Parameters#

NameType
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 clipboard
1const layers = document.layers
2layers && 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 clipboard
1// duplicate a layer
2const copyLayer = await layer.duplicate()
3
4// extract to a new document
5const exportDoc = psApp.documents[1]
6const exportedLayer = await layer.duplicate(exportDoc)

Parameters#

NameType
relativeObject?Document | Layer
insertionLocation?ElementPlacement
name?string

flip#

async : Promise<void>

Flips the layer on one or both axis.

Copied to your clipboard
1// flip horizontally
2await layer.flip.horizontal()

Parameters#

NameTypeDescription
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 clipboard
1// link two layers together
2const linkedLayers = strokes.link(fillLayer)
3linkedLayers.forEach((layer) => console.log(layer.name))
4> "strokes"
5> "fillLayer"

Parameters#

NameType
targetLayerLayer

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#

NameType
relativeObjectLayer
insertLocationElementPlacement

rasterize#

async : Promise<void>

Converts the targeted contents in the layer into a flat, raster image.

Parameters#

NameType
targetRasterizeType

rotate#

async : Promise<void>

Rotates the layer.

Copied to your clipboard
1// rotate 90 deg counter clockwise
2await layer.rotate(-90)
3
4// rotate 90 deg clockwise relative to top left corner
5let anchorPos = require('photoshop').constants.AnchorPosition
6await layer.rotate(90, anchorPos.TOPLEFT)

Parameters#

NameTypeDescription
anglenumber | AngleValueAngle to rotate the layer by in degrees
anchor?AnchorPositionAnchor position to rotate around
options?object-
options.interpolation?ResampleMethodInterpolation method to use when resampling the image

scale#

async : Promise<void>

Scales the layer. Renamed from resize in ExtendScript.

Copied to your clipboard
1await layer.scale(80, 80)
2
3// Scale the layer to be a quarter of the size relative to bottom left corner
4let anchorPos = require('photoshop').constants.AnchorPosition
5await layer.scale(50, 50, anchorPos.BOTTOMLEFT)

Parameters#

NameTypeDescription
widthnumber | PercentValueNumeric percentage to scale layer horizontally
heightnumber | PercentValueNumeric percentage to scale layer vertically
anchor?AnchorPositionAnchor position to rotate around
options?object-
options.interpolation?ResampleMethodInterpolation 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 clipboard
1// parellelogram shape
2await layer.skew(-15, 0)

Parameters#

NameTypeDescription
angleHnumber | AngleValueHorizontal angle to skew by
angleVnumber | AngleValueVertical angle to skew by
options?object-
options.interpolation?ResampleMethod-

translate#

async : Promise<void>

Moves the layer (translation).

Copied to your clipboard
1// Translate the layer to the left by 200px
2await layer.translate(-200, 0)
3
4// move the layer one height down
5let xOffsetPct = {_unit: "percentUnit", _value: 0};
6let yOffsetPct = {_unit: "percentUnit", _value: 100};
7await layer.translate(xOffsetPct, yOffsetPct);

Parameters#

NameTypeDescription
horizontalnumber | PercentValue | PixelValueNumeric value to offset layer by in pixels or percent
verticalnumber | PercentValue | PixelValueNumeric value to offset layer by in pixels or percent

unlink#

async : Promise<void>

Unlinks the layer from any existing links.

Copied to your clipboard
1// detach layer from any existing links
2await layer.unlink()
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.