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.

Copied to your clipboard
group.layers.forEach((layer) => {
layer.visible = true;
})

Properties

NameTypeAccessMin VersionDescription
allLocked
boolean
R W
22.5
When set to true, prevents edits to pixels and properties of this layer.
blendMode
R W
22.5
The blend mode of the layer. Fixes in Photoshop 24.2: - Now it will throw error when passing non-existent blend mode - Also will throw error if combination of document color mode, bit depth and blend mode is not possible instead of failing silently - Prior this version it was possible to set blend mode for background layer which turned it into regular layer as a side effect and also changed its ID. Not it will throw error instead since these side effects are not expected to happen
bounds
R
22.5
Bounds of the layer, including the effects.
boundsNoEffects
R
22.5
Bounds of the layer excluding effects.
document
R
23.0
The document that contains this layer.
fillOpacity
number
R W
23.0
The fill opacity of the layer, in percentage.
filterMaskDensity
number
R W
23.0
The density of the filter mask, in percentage.
filterMaskFeather
number
R W
23.0
The feather of the filter mask between 0.0 and 1000.0.
id
number
R
22.5
ID of the layer, can be used for making batchPlay calls.
isBackgroundLayer
boolean
R
22.5
True when the layer is the special Background layer.
isClippingMask
boolean
R W
23.0
Whether the layer is being used as a clipping mask.
kind
R
22.5
The kind of the layer.
layerMaskDensity
number
R W
23.0
The density of the layer mask, in percentage.
layerMaskFeather
number
R W
23.0
The feather of the layer mask between 0.0 and 1000.0.
layers
R
23.0
The layers inside this group layer.
linkedLayers
R
22.5
Layers linked to this layer. See Layer.link
locked
boolean
R
22.5
True if any property of this layer is locked.
name
string
R W
22.5
Name of the layer.
opacity
number
R W
22.5
The master opacity of the layer, in percent.
parent
R
22.5
The group layer that contains this layer. It will return null if the layer is a top layer in the document.
pixelsLocked
boolean
R W
22.5
When set to true, prevents the pixels of this layer from being edited.
positionLocked
boolean
R W
22.5
When set to true, prevents the layer from being moved.
textItem
R
24.2
The object that contains properties and methods related to Text for Layers whose `kind` is equal to `LayerKind.TEXT`
transparentPixelsLocked
boolean
R W
22.5
When set to true, prevents the transparent pixels from being edited
typename
string
R
23.0
The class name of the referenced object: "Layer".
vectorMaskDensity
number
R W
23.0
The density of the vector mask, in percentage.
vectorMaskFeather
number
R W
23.0
The feather of the vector mask between 0.0 and 1000.0.
visible
boolean
R W
22.5
True when the layer is visible.

Methods

applyAddNoise

23.5

async : Promise<void>

Applies the Add Noise filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
amount
number
Percentage of noise applied [0.1,400].
distribution
Distribution method to use.
monochromatic
boolean
Adds black and white noise if true.

applyAverage

23.5

async : Promise<void>

Applies the Average filter.

Unsupported color modes: Indexed Color, Bitmap


applyBlur

23.5

async : Promise<void>

Applies the Blur filter.

Unsupported color modes: Indexed Color, Bitmap


applyBlurMore

23.5

async : Promise<void>

Applies the Blur More filter.

Unsupported color modes: Indexed Color, Bitmap


applyClouds

23.5

async : Promise<void>

Applies the Clouds filter.

Unsupported color modes: Indexed Color, Bitmap


applyCustomFilter

23.5

async : Promise<void>

Applies the Custom filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
characteristics
number[]
Square matrix (5 x 5) used to perform filter operation.
scale
number
The value by which to divide the sum of the pixel values included in the calculation
offset
number
The value to be added to the result of the scale calculation.

applyDeInterlace

23.5

async : Promise<void>

Applies the De-Interlace filter.

Unsupported color modes: Indexed Color, Bitmap, CMYK 8 bits, CMYK 16 bits, Duotone 8 bits

Parameters

NameTypeDescription
eliminateFields
Eliminate EVENFIELDS or ODDFIELDS field order.
createFields
Create fields by either DUPLICATION or INTERPOLATION.

applyDespeckle

23.5

async : Promise<void>

Applies the Despeckle filter.

Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits


applyDifferenceClouds

23.5

async : Promise<void>

Applies the Difference Clouds filter.

Unsupported color modes: Indexed Color, Bitmap, Lab 8 bits, Lab 16 bits


applyDiffuseGlow

23.5

async : Promise<void>

Applies the Diffuse Glow filter.

Supported color modes: RGB 8 bits, Duotone 8 bits, Grayscale 8 bits, Multichannel 8 bits

Parameters

NameTypeDescription
graininess
number
The amount of grain [0,10].
glowAmount
number
The glow amount [0,20].
clearAmount
number
The clear amount [0,20].

applyDisplace

23.5

async : Promise<void>

Applies the Displace filter using the specified horizontal and vertical scale, mapping type, treatment of undistorted areas, and path to the distortion image map.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
horizontalScale
number
How much to scale in the direction of width [-999,999].
verticalScale
number
How much to scale in the direction of height [-999,999].
displacementType
Describes how the displacement map fits the image if the image is not the same size as the map.
undefinedAreas
The method used to treat undistorted areas or areas left blank in an image to which the filter in the Distor category has been applied.
displacementMapFile
File
Path to the distortion image map.

applyDustAndScratches

23.5

async : Promise<void>

Applies the Dust & Scratches filter.

Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits

Parameters

NameTypeDescription
radius
number
The radius of the filter in pixels [1,100].
threshold
number
The lower the amount, the stronger the effect [0,255].

applyGaussianBlur

23.5

async : Promise<void>

Applies the Gaussian Blur filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
radius
number
The radius of the filter in pixels [0.1,250].

applyGlassEffect

23.5

async : Promise<void>

Applies the Glass filter.

Supported color modes: RGB 8 bits, Duotone 8 bits, Grayscale 8 bits, Multichannel 8 bits

Parameters

NameTypeDefault valueDescription
distortion
number
-
Change the amount the glass distorts the image [0,20].
smoothness
number
-
Change the smoothness of the glass [1,15].
scaling
number
-
The percentage value to scale by [50,200].
invert
boolean
false
Invert the glass (default: false).
texture
-
The type of glass texture. This argument is ignored if "textureFile" is provided. (default: TextureType.CANVAS)
textureFile?
File
-
Mapping for glass distortion (optional).

applyHighPass

23.5

async : Promise<void>

Applies the High Pass filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
radius
number
The width of high pass filter (pixels) [0.1,1000].

applyImage

24.5

async : Promise<void>

The applyImage method lets you blend one image’s layer and channel (the source) with a this layer (the target). This will change pixels contained in this layer. Performs Image > Apply Image on the document. See the ApplyImageOptions object for more info and examples.

Parameters

NameTypeDescription
applyImageOptions
Option object for applyImage.

applyLensBlur

23.5

async : Promise<void>

Applies the Lens Blur filter.

Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits

Parameters

NameTypeDefault valueDescription
source
-
The source for the depth map (default: DepthMapSource.NONE)
focalDistance
number
0
The blur focal distance for the depth map [0,255] (default: 0).
invertDepthMask
boolean
false
True if the depth map is inverted (default: false)
shape
-
The shape of the iris (default: Geometry.HEXAGON)
radius
number
15
The radius of the iris [0,100] (default: 15)
bladeCurvature
number
0
The blade curvature of the iris [0,100] (default: 0)
rotation
number
0
The rotation of the iris [0,360] (default: 0)
brightness
number
0
The brightness for the specular highlights [0,100] (default: 0)
threshold
number
0
The threshold for the specular highlights [0,255] (default: 0)
amount
number
0
The amount of noise [0,100] (default: 0)
distribution
-
The distribution value for the noise (default: NoiseDistribution.UNIFORM)
monochromatic
boolean
false
True if the noise is monochromatic (default: false)

applyLensFlare

23.5

async : Promise<void>

Applies the Lens Flare filter.

Supported color modes: RGB 8 bits, RGB 16 bits, RGB 32 bits

Parameters

NameTypeDescription
brightness
number
Percentage of brightness applied [10,300].
flareCenter
object
The flare center {x: number, y: number}.
flareCenter.x
number
The horizontal coordinate in pixels.
flareCenter.y
number
The vertical coordinate in pixels.
lensType
The lens type used to produce the effect (default: LensType.ZOOMLENS).

applyMaximum

23.5

Promise<void>

Applies the Maximum filter

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
radius
number
The radius of the filter in pixels.
Integer in the range [1,500] when using SQUARENESS.
Float in the range [0.2,500] when using ROUNDNESS.
preserveShape
Favor hard corners or smooth curves around the edges
(default: PreserveShape.SQUARENESS)

applyMedianNoise

23.5

Promise<void>

Applies the Median filter

Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits

Parameters

NameTypeDescription
radius
number
The radius of the filter in pixels [1,500]

applyMinimum

23.5

Promise<void>

Applies the Minimum filter

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
radius
number
The radius of the filter in pixels.
Integer in the range [1,500] when using SQUARENESS.
Float in the range [0.2,500] when using ROUNDNESS.
preserveShape
Favor hard corners or smooth curves around the edges
(default: PreserveShape.SQUARENESS)

applyMotionBlur

23.5

Promise<void>

Applies the Motion Blur filter

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
angle
number
The angle the blur effect will be applied at (degrees) [-360,360]
distance
number
The amount of blur [1,2000]

applyNTSC

23.5

Promise<void>

Applies the NTSC Colors filter

Supported color modes: RGB 8 bits, RGB 16 bits, RGB 32 bits


applyOceanRipple

23.5

Promise<void>

Applies the Ocean Ripple filter

Supported color modes: RGB 8 bits, Duotone 8 bits, Grayscale 8 bits, Multichannel 8 bits

Parameters

NameTypeDescription
size
number
The Ripple size [1,15]
magnitude
number
The Ripple magnitude [1,20]

applyOffset

23.5

Promise<void>

Applies the Offset filter

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
horizontal
number
The horizontal offset [-2 * doc.width, 2 * doc.width]
vertical
number
The vertical offset [-2 * doc.height, 2 * doc.height]
undefinedAreas
Method to use to fill the empty space left by the offset
(default: OffsetUndefinedAreas.WRAPAROUND).

applyPinch

23.5

async : Promise<void>

Applies the Pinch filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
amount
number
The pinch amount. Negative value creates effect of expansion and positive creates effect of contraction. [-100,100]

applyPolarCoordinates

23.5

async : Promise<void>

Applies the Polar Coordinates filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
conversion
The conversion type.

applyRipple

23.5

async : Promise<void>

Applies the Ripple filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
amount
number
The ripple amount. [-999,999]
size
The ripple size.

applySharpen

23.5

async : Promise<void>

Applies the Sharpen filter.

Unsupported color modes: Indexed Color, Bitmap


applySharpenEdges

23.5

async : Promise<void>

Applies the Sharpen Edges filter.

Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits


applySharpenMore

23.5

async : Promise<void>

Applies the Sharpen More filter.

Unsupported color modes: Indexed Color, Bitmap


applyShear

23.5

async : Promise<void>

Applies the the Shear filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
curve
{ x: number ; y: number }[]
Specification of the shear curve in points as coordinates object with x, y properties e.g.in the format [{x:-20, y:1}, {x:30, y:128}]. Any number higher than 2 of coordinate objects can be specified. For "x" coordinate it is recommended to use range [-63,64] and for "y" coordinate use range [1,128]. For bests results please make sure that first point has 0 at "y" axis and last point has 128 at "y" axis. Also sort points by "y" value in ascending order. Follow these rules to ensure that curve will be shown correctly in dialog UI.
undefinedArea
The treatment of areas left blank by the distortion.

applySmartBlur

24.0

async : Promise<void>

Applies the Smart Blur filter.

Supported color modes: RGB 8 bits, CMYK 8 bits, Duotone 8 bits,

Grayscale 8 bits, Lab 8 bits, Multichannel 8 bits

Parameters

NameTypeDescription
radius
number
The blur radius [0.1,100].
threshold
number
The blur threshold [0.1,100].
blurQuality
The smoothness or graininess of the blurred image.
mode
The smart blur mode.

applySpherize

24.0

async : Promise<void>

Applies the Spherize filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
amount
number
The amount of distortion [-100,100].
mode
The distortion mode.

applyTwirl

23.5

async : Promise<void>

Applies the Twirl filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
angle
number
The amount of twirl to apply (degrees) [-999,999]

applyUnSharpMask

24.0

async : Promise<void>

Applies the Unsharp Mask filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
amount
number
The amount of sharpening (as a whole number percentage) [1,500].
radius
number
The radius in pixels [0.1,1000].
threshold
number
The contrast threshold [0,255].

applyWave

24.0

async : Promise<void>

Applies the Wave filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
generatorNumber
number
The whole number of generators [1,999].
minimumWavelength
number
The minimum wave length [1,(maximum wave length - 1)] (whole number).
maximumWavelength
number
The maximum wave length [(minimum wave length + 1),999] (whole number).
minimumAmplitude
number
The minimum amplitude [1,(maximum amplitude - 1)] (whole number).
maximumAmplitude
number
The maximum amplitude [(minimum amplitude + 1),999] (whole number).
horizontalScale
number
The amount of horizontal scale (as a percentage) [1,100] (whole number).
verticalScale
number
The amount of vertical scale (as a percentage) [1,100] (whole number).
waveType
The wave type (optional).
undefinedAreas
The treatment of areas left blank by the distortion (optional).
randomSeed
number
The random seed (optional).

applyZigZag

24.0

async : Promise<void>

Applies the ZigZag filter.

Unsupported color modes: Indexed Color, Bitmap

Parameters

NameTypeDescription
amount
number
The amount of zigzag [-100,100].
ridges
number
The number of ridges [0,20].
style
The zigzag style.

bringToFront

23.0

void

Moves the layer to a position above the topmost layer or group.


clear

23.0

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

23.0

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
await layer.copy(true)
await layer.copy()

Parameters

NameType
merge?
boolean

cut

23.0

async : Promise<void>

Cuts the layer contents to the clipboard. If no selection is found then select all the pixels and then cut.


delete

23.0

void

Deletes this layer from the document.

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

duplicate

23.0

async : Promise<Layer>

Duplicates the layer, creating a copy above it in layer stack, and returns the newly created layer.

Copied to your clipboard
// duplicate a layer
const copyLayer = await layer.duplicate()
// extract to a new document
const exportDoc = psApp.documents[1]
const exportedLayer = await layer.duplicate(exportDoc)

Parameters

NameType
relativeObject?
insertionLocation?
name?
string

flip

23.0

async : Promise<void>

Flips the layer on one or both axis.

Copied to your clipboard
// flip horizontally
await 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

23.0

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
// link two layers together
const linkedLayers = strokes.link(fillLayer)
linkedLayers.forEach((layer) => console.log(layer.name))
> "strokes"
> "fillLayer"

Parameters

NameType
targetLayer

merge

23.0

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

23.0

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
relativeObject
insertLocation

rasterize

23.0

async : Promise<void>

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

Parameters

NameType
target

rotate

23.0

async : Promise<void>

Rotates the layer.

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

Parameters

NameTypeDescription
angle
number | AngleValue
Angle to rotate the layer by in degrees
anchor?
Anchor position to rotate around
options?
object
-
options.interpolation?
Interpolation method to use when resampling the image

scale

23.0

async : Promise<void>

Scales the layer.

Renamed from resize in ExtendScript.

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

Parameters

NameTypeDescription
width
number | PercentValue
Numeric percentage to scale layer horizontally
height
number | PercentValue
Numeric percentage to scale layer vertically
anchor?
Anchor position to rotate around
options?
object
-
options.interpolation?
Interpolation method to use when resampling the image

sendToBack

23.0

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

23.0

async : Promise<void>

Applies a skew to the layer.

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

Parameters

NameTypeDescription
angleH
number | AngleValue
Horizontal angle to skew by
angleV
number | AngleValue
Vertical angle to skew by
options?
object
-
options.interpolation?
-

translate

23.0

async : Promise<void>

Moves the layer (translation).

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

Parameters

NameTypeDescription
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

23.0

async : Promise<void>

Unlinks the layer from any existing links.

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