Layer
A Photoshop Layer. Ultimately, this will have subclasses denoting all layer types.
Layer
Accessors
bounds
• get bounds(): PsCommon.Bounds
Bounds of the layer, including the effects
Copied to your clipboardconst { left, top, right, bottom } = layer.bounds
boundsNoEffects
• get boundsNoEffects(): PsCommon.Bounds
Bounds of the layer excluding effects
Copied to your clipboardconst { left, top, right, bottom } = layer.boundsNoEffects
kind
• get kind(): LayerKind
Kind of the layer
Copied to your clipboard1if (layer.kind === LayerKind.TEXT) {2 ...3}
linkedLayers
• get linkedLayers(): Layer[]
Layers linked to this layer
Copied to your clipboard1const layers = layerAA.linkedLayers2layers.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 clipboard1const layers = document.layers2layers && 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 clipboard1// duplicate a layer2const copyLayer = await layer.duplicate()34// extract to a new document5const exportDoc = psApp.documents[1]6const exportedLayer = await layer.duplicate(exportDoc)
async
Parameters:
Name | Type | Description |
---|---|---|
targetDocument? | Document | if 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 clipboard1// flip horizontally2await layer.flip("horizontal")
async
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
▸ 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 clipboard1// link two layers together2const linkedLayers = strokes.link(fillLayer)3linkedLayers.forEach((layer) => console.log(layer.name))4> "strokes"5> "fillLayer"
Parameters:
Name | Type | Description |
---|---|---|
targetLayer | Layer | layer 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 clipboard1foregroundLayer.moveAbove(backingLayer)2// foregroundLayer3// backingLayer
Parameters:
Name | Type | Description |
---|---|---|
target? | LayerTypes | layer 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 clipboard1backingLayer.moveBelow(foregroundLayer)2// foregroundLayer3// backingLayer
Parameters:
Name | Type | Description |
---|---|---|
target? | LayerTypes | layer 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 clipboard1// nudge the layer to the left by 200px2await layer.nudge(-200, 0)34// move the layer one height down5let percent = (v) => ({ _unit: "percentUnit", _value: v })6await layer.nudge(percent(0), percent(100))
async
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 |
rotate
▸ rotate(angle
: number | AngleValue, options?
: object): Promise‹void›
Rotates the layer.
Copied to your clipboard1// rotate 90 deg counter clockwise2await layer.rotate(-90)
async
Parameters:
▪ angle: number | AngleValue
Angle to rotate the layer by in degrees
▪Optional
options: object
Name | Type | Description |
---|---|---|
interpolation? | InterpolationMethod | Interpolation 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 clipboardawait 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
Name | Type | Description |
---|---|---|
interpolation? | InterpolationMethod | Interpolation 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 clipboard1// parellelogram shape2await 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
Name | Type |
---|---|
interpolation? | InterpolationMethod |
unlink
▸ unlink(): Promise‹void›
Unlinks the layer from any existing links.
Copied to your clipboard1// detach layer from any existing links2await layer.unlink()
async