Edit in GitHubLog an issue

Layer

A Photoshop Layer. Ultimately, this will have subclasses denoting all layer types.

Accessors#

bounds#

get bounds(): PsCommon.Bounds

Bounds of the layer, including the effects

Copied to your clipboard
const { left, top, right, bottom } = layer.bounds

boundsNoEffects#

get boundsNoEffects(): PsCommon.Bounds

Bounds of the layer excluding effects

Copied to your clipboard
const { left, top, right, bottom } = layer.boundsNoEffects

kind#

get kind(): LayerKind

Kind of the layer

Copied to your clipboard
1if (layer.kind === LayerKind.TEXT) {
2 ...
3}

linkedLayers#

get linkedLayers(): Layer[]

Layers linked to this layer

Copied to your clipboard
1const layers = layerAA.linkedLayers
2layers.forEach((layer) => {
3 ...
4})

parent#

get parent(): GroupLayer | null

The group layer this layer is in, null if layer has no parent

Methods#

delete#

delete(): void

Deletes this layer from the document.

Copied to your clipboard
1const layers = document.layers
2layers && layers[0] && layers[0].delete()

number of layer elements deleted


duplicate#

duplicate(targetDocument?: Document, name?: string): 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)

async

Parameters:

NameTypeDescription
targetDocument?Documentif specified, duplicate to a different document target.
name?string-

flip#

flip(axis: "horizontal" | "vertical" | "both"): Promise‹void›

Flips the layer on one or both axis.

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

async

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#

link(targetLayer: Layer): 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:

NameTypeDescription
targetLayerLayerlayer to link with

array of linked layers


moveAbove#

moveAbove(target?: LayerTypes): void

Moves the layer to a position above the target layer or group. If no target layer is defined, move this layer up one slot.

Copied to your clipboard
1foregroundLayer.moveAbove(backingLayer)
2// foregroundLayer
3// backingLayer

Parameters:

NameTypeDescription
target?LayerTypeslayer or group that will proceed this layer.

moveBelow#

moveBelow(target?: LayerTypes): void

Moves the layer to a position below the target layer or group. If no target layer is defined, move this layer down one slot.

Copied to your clipboard
1backingLayer.moveBelow(foregroundLayer)
2// foregroundLayer
3// backingLayer

Parameters:

NameTypeDescription
target?LayerTypeslayer or group that will preceed this layer.

nudge#

nudge(horizontal: number | PercentValue | PixelValue, vertical: number | PercentValue | PixelValue): Promise‹void›

Moves the layer.

Copied to your clipboard
1// nudge the layer to the left by 200px
2await layer.nudge(-200, 0)
3
4// move the layer one height down
5let percent = (v) => ({ _unit: "percentUnit", _value: v })
6await layer.nudge(percent(0), percent(100))

async

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

rotate#

rotate(angle: number | AngleValue, options?: object): Promise‹void›

Rotates the layer.

Copied to your clipboard
1// rotate 90 deg counter clockwise
2await layer.rotate(-90)

async

Parameters:

angle: number | AngleValue

Angle to rotate the layer by in degrees

Optional options: object

NameTypeDescription
interpolation?InterpolationMethodInterpolation method to use when resampling the image @default InterpolationMethod.bilinear

scale#

scale(width: number | PercentValue, height: number | PercentValue, options?: object): Promise‹void›

Scales the layer.

Copied to your clipboard
await layer.scale(80, 80)

async

Parameters:

width: number | PercentValue

Numeric percentage to scale layer horizontally

height: number | PercentValue

Numeric percentage to scale layer vertically

Optional options: object

NameTypeDescription
interpolation?InterpolationMethodInterpolation method to use when resampling the image @default InterpolationMethod.bilinear

skew#

skew(angleH: number | AngleValue, angleV: number | AngleValue, options?: object): Promise‹void›

Applies a skew to the layer.

Copied to your clipboard
1// parellelogram shape
2await layer.skew(-15, 0)

async

Parameters:

angleH: number | AngleValue

Horizontal angle to skew by

angleV: number | AngleValue

Vertical angle to skew by

Optional options: object

NameType
interpolation?InterpolationMethod

unlink#

unlink(): Promise‹void›

Unlinks the layer from any existing links.

Copied to your clipboard
1// detach layer from any existing links
2await layer.unlink()

async

Copyright © 2021 Adobe. All rights reserved.