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.
group.layers.forEach((layer) => {
layer.visible = true;
})
Properties
Methods
applyAddNoise
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Add Noise filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
amountmonochromaticapplyAverage
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Average filter.
Unsupported color modes: Indexed Color, Bitmap
applyBlur
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Blur filter.
Unsupported color modes: Indexed Color, Bitmap
applyBlurMore
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Blur More filter.
Unsupported color modes: Indexed Color, Bitmap
applyClouds
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Clouds filter.
Unsupported color modes: Indexed Color, Bitmap
applyCustomFilter
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Custom filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
characteristicsscaleoffsetapplyDeInterlace
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the De-Interlace filter.
Unsupported color modes: Indexed Color, Bitmap, CMYK 8 bits, CMYK 16 bits, Duotone 8 bits
Parameters
applyDespeckle
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Despeckle filter.
Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits
applyDifferenceClouds
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Difference Clouds filter.
Unsupported color modes: Indexed Color, Bitmap, Lab 8 bits, Lab 16 bits
applyDiffuseGlow
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Diffuse Glow filter.
Supported color modes: RGB 8 bits, Duotone 8 bits, Grayscale 8 bits, Multichannel 8 bits
Parameters
graininessglowAmountclearAmountapplyDisplace
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> 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
horizontalScaleverticalScaledisplacementTypeundefinedAreasdisplacementMapFileapplyDustAndScratches
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Dust & Scratches filter.
Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits
Parameters
radiusthresholdapplyGaussianBlur
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Gaussian Blur filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
radiusapplyGlassEffect
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Glass filter.
Supported color modes: RGB 8 bits, Duotone 8 bits, Grayscale 8 bits, Multichannel 8 bits
Parameters
distortionsmoothnessscalinginverttexturetextureFile?applyHighPass
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the High Pass filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
radiusapplyImage
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.5</span>
<br/> 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
applyLensBlur
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Lens Blur filter.
Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits
Parameters
focalDistance0).invertDepthMaskfalse)radiusbladeCurvature0)rotation0)brightness0)threshold0)amount0)distributionNoiseDistribution.UNIFORM)monochromaticfalse)applyLensFlare
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Lens Flare filter.
Supported color modes: RGB 8 bits, RGB 16 bits, RGB 32 bits
Parameters
brightnessflareCenter{x: number, y: number}.flareCenter.xflareCenter.yapplyMaximum
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the Maximum filter
Unsupported color modes: Indexed Color, Bitmap
Parameters
radiusSQUARENESS. Float in the range [0.2,500] when using ROUNDNESS.preserveShapePreserveShape.SQUARENESS)applyMedianNoise
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the Median filter
Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits
Parameters
radiusapplyMinimum
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the Minimum filter
Unsupported color modes: Indexed Color, Bitmap
Parameters
radiusSQUARENESS. Float in the range [0.2,500] when using ROUNDNESS.preserveShapePreserveShape.SQUARENESS)applyMotionBlur
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the Motion Blur filter
Unsupported color modes: Indexed Color, Bitmap
Parameters
angledistanceapplyNTSC
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the NTSC Colors filter
Supported color modes: RGB 8 bits, RGB 16 bits, RGB 32 bits
applyOceanRipple
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the Ocean Ripple filter
Supported color modes: RGB 8 bits, Duotone 8 bits, Grayscale 8 bits, Multichannel 8 bits
Parameters
sizemagnitudeapplyOffset
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> Promise<void>
Applies the Offset filter
Unsupported color modes: Indexed Color, Bitmap
Parameters
horizontalverticalundefinedAreasOffsetUndefinedAreas.WRAPAROUND).applyPinch
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Pinch filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
amountapplyPolarCoordinates
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Polar Coordinates filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
applyRipple
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Ripple filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
applySharpen
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Sharpen filter.
Unsupported color modes: Indexed Color, Bitmap
applySharpenEdges
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Sharpen Edges filter.
Unsupported color modes: Indexed Color, Bitmap, RGB 32 bits, Grayscale 32 bits
applySharpenMore
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Sharpen More filter.
Unsupported color modes: Indexed Color, Bitmap
applyShear
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the the Shear filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
curvex: number ; y: number }[]applySmartBlur
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> 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
radiusthresholdapplySpherize
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> async : Promise<void>
Applies the Spherize filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
amountapplyTwirl
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.5</span>
<br/> async : Promise<void>
Applies the Twirl filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
angleapplyUnSharpMask
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> async : Promise<void>
Applies the Unsharp Mask filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
amountradiusthresholdapplyWave
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> async : Promise<void>
Applies the Wave filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
generatorNumberminimumWavelengthmaximumWavelengthminimumAmplitudemaximumAmplitudehorizontalScaleverticalScalerandomSeedapplyZigZag
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> async : Promise<void>
Applies the ZigZag filter.
Unsupported color modes: Indexed Color, Bitmap
Parameters
amountridgesbringToFront
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> void
Moves the layer to a position above the topmost layer or group.
clear
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> 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
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> 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).
await layer.copy(true)
await layer.copy()
Parameters
merge?cut
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Cuts the layer contents to the clipboard. If no selection is found then select all the pixels and then cut.
delete
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> void
Deletes this layer from the document.
const layers = document.layers
layers && layers[0] && layers[0].delete()
duplicate
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise <Layer>
Duplicates the layer, creating a copy above it in layer stack, and returns the newly created layer.
// 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
flip
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Flips the layer on one or both axis.
// flip horizontally
await layer.flip(constants.FlipAxis.HORIZONTAL);
Parameters
link
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> 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.
// link two layers together
const linkedLayers = strokes.link(fillLayer)
linkedLayers.forEach((layer) => console.log(layer.name))
> "strokes"
> "fillLayer"
Parameters
targetLayermerge
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> 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
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> 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
rasterize
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Converts the targeted contents in the layer into a flat, raster image.
Parameters
targetrotate
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Rotates the layer.
// 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
angleoptions?scale
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Scales the layer.
Renamed from resize in ExtendScript.
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
widthheightoptions?sendToBack
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> 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
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Applies a skew to the layer.
// parellelogram shape
await layer.skew(-15, 0)
Parameters
angleHangleVoptions?translate
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Moves the layer (translation).
// 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
horizontalverticalunlink
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Unlinks the layer from any existing links.
// detach layer from any existing links
await layer.unlink()