Save the document to a desired file type.
For operations that require a UXP File token, use the UXP storage APIs to generate one.
Save the document as a BMP file.
Save the document as a GIF file.
Save the document as a JPG file.
Save the document as a PNG file.
Save the document as a PSB file.
Save the document as a PSD file.
ReadonlyselectionThe object containing the document's currently active selection.
The history state that history brush tool will use as its source.
Currently active history state of the document.
Selects the given history state to be the active one.
The artboards in the document.
Background layer, if it exists.
The bits per color channel.
All channels in the document.
Check whether this a Photoshop cloud document.
Local directory for this cloud document.
Name of the color profile.
Valid only when colorProfileType is CUSTOM or WORKING, returns "None" otherwise.
Whether the document uses the working color profile, a custom profile, or no profile.
The collection of ColorSamplers present in the document.
Deprecated since these channels are component not composite.
Use componentChannels above.
The collection of CountItems present in the document.
The collection of Guides present in the document.
Document's height in pixels.
A histogram containing the number of pixels at each color intensity level for the component channel. The array contains 256 members.
Valid only when mode = DocumentMode.{RGB,CMYK,INDEXEDCOLOR}
History states of the document.
The internal ID of this document will remain valid as long as this document is open. It can be used for batchPlay calls to refer to this document.
The layer comps present in the document.
The layers in the document at the top level of the layer/group hierarchy.
The color mode. To change it, please use Document.changeMode.
The name of the document.
Full file system path to this document, or the identifier if it is a cloud document.
The collection of paths in this document, as shown in the Paths panel.
The (custom) pixel aspect ratio to use.
The state of Quick Mask mode. If true, the app is in Quick Mask mode.
Document's resolution (in pixels per inch).
True if the document has been saved since the last change.
Document title.
The class name of the referenced object: "Document".
Document's width in pixels.
The Calculations command lets you blend two individual channels from one or more source images. You can then apply the results to a new image or to a new channel or selection in the active image.
Performs Image > Calculations on the document. See the CalculationsOptions object for more info and examples.
Known issue: currently calculations requires having exactly one unlocked pixel layer being selected otherwise it won't work. In future there should not be any layer requirements since this cannot output into layer.
Option object for the calculations.
const doc = app.activeDocument;
const options = {
source1: {
document: doc,
layer: doc.layers[0],
channel: constants.CalculationsChannel.GRAY
invert: true
},
source2: {
document: doc,
layer: constants.CalculationsLayer.MERGED,
channel: doc.channels[2]
},
blending: constants.CalculationsBlendMode.DARKEN,
opacity: 50,
result: constants.CalculationsResult.NEWCHANNEL
};
doc.calculations(options);
Changes the color mode of the document.
The color mode to change to.
Optionaloptions: BitmapConversionOptions | IndexedConversionOptionsOptional conversion options.
Closes the document, showing a prompt to save unsaved changes if specified.
OptionalsaveDialogOptions: SaveOptionsBy default, prompts a save dialog if there are unsaved changes.
Close the document, discarding all unsaved changes.
Changes the color profile.
destinationProfile must be either a string that names the color mode,
or one of these below, meaning of the working color spaces or Lab color.
"Working RGB", "Working CMYK", "Working Gray", "Lab Color"
The profile name or working space.
The rendering intent.
OptionalblackPointCompensation: booleanWhether to use black point compensation.
Optionaldither: booleanWhether to use dithering.
General form of the kind-specific methods below. See those methods for more information. Create a new layer of the given kind. With no arguments, a pixel layer will be created.
The options object will have properties specific to the kind, though all layers share a basic set of properties common to all.
The override signatures below are provided as type guardrails to help ensure the options provided match the layer kind.
Create a new pixel layer.
The kind of layer to create.
Optionaloptions: PixelLayerCreateOptionsThe options for creation, including general layer options and those specific to the layer kind.
Create a new layer group.
The kind of layer to create.
Optionaloptions: GroupLayerCreateOptionsThe options for creation, including general layer options and those specific to the layer kind.
Create a layer group using options described by GroupLayerCreateOptions.
Optionaloptions: GroupLayerCreateOptionsThe options for creation.
const myEmptyGroup = await doc.createLayerGroup()
const myGroup = await doc.createLayerGroup({name: "myLayer", opacity: 80, blendMode: "colorDodge"})
const nonEmptyGroup = await doc.createLayerGroup({name: "group", fromLayers: [layer1, layer2]})
const selectedGroup = await doc.createLayerGroup({name: "group", fromLayers: doc.activeLayers})
Create a pixel layer using options described by PixelLayerCreateOptions.
Optionaloptions: PixelLayerCreateOptionsThe options for creation.
Create a text layer using options described by TextLayerCreateOptions.
Optionaloptions: TextLayerCreateOptionsThe options for creation.
Crops the document to the given bounds.
The crop area bounds.
Optionalangle: numberAngle to rotate the crop area (default: 0).
Optionalwidth: numberWidth of the crop area (default: 0).
Optionalheight: numberHeight of the crop area (default: 0).
Creates a duplicate of the document, making the duplicate active.
The optional parameter name provides the name for the duplicated document.
The optional parameter mergeLayersOnly indicates whether to only duplicate merged layers.
Optionalname: stringName for the duplicated document.
OptionalmergeLayersOnly: booleanWhether to only duplicate merged layers.
Duplicates given layer(s), creating all copies above the top most one in layer stack, and returns the newly created layers.
// duplicate some layers
const layerCopies = await document.duplicateLayers([layer1, layer3])
layerCopies.forEach((layer) => { layer.blendMode = 'multiply' })
Flatten all layers in the document. The remaining layer will become Background.
Applies generative upscaling to the currently selected layer(s) using AI-powered upscaling technology.
The model to use for upscaling.
The options for upscaling.
Merges all visible layers in the document into a single layer.
In contrast to flatten, mergeVisibleLayers will not convert the remaining layer
to Background if no Background already exists. If not Background, then the name of the
merged layer will be either that of the top of the selected layers or the top layer.
Pastes the contents of the clipboard into the document. If the optional argument is set to true and a selection is active, the contents are pasted into the selection.
OptionalintoSelection: booleanWhether to use an active selection as the target for the paste.
Converts all layers to pixel layers.
Changes the size of the document, but does not scale the image. To scale the image size, see resizeImage.
Numeric value of new width in pixels.
Numeric value of new height in pixels.
Optionalanchor: AnchorPositionAnchor point for resizing, by default will resize an equal amount on all sides.
Changes the size of the image by scaling the dimensions to meet the targeted number of pixels.
Optionalwidth: numberNumeric value of new width in pixels.
Optionalheight: numberNumeric value of new height in pixels.
Optionalresolution: numberImage resolution in pixels per inch (ppi).
OptionalresampleMethod: ResampleMethodMethod used during image interpolation.
Optionalamount: numberNumeric value that controls the amount of noise value when using preserve details 0..100.
Expands the document to show clipped sections.
Rotates the image clockwise in given angle, expanding canvas if necessary. (Previously rotateCanvas)
The angle in degrees to rotate.
Returns a SolidColor object sampled from the document at the given position.
The point to sample {x: number, y: number}.
The horizontal coordinate in pixels.
The vertical coordinate in pixels.
A SolidColor instance of the sampled pixel.
Creates a single history state encapsulating everything that is done in the callback, only for this document. All changes to the document should be done in this callback.
Note: If you make changes to any other document, those changes will not be suspended in the same history state.
The callback is passed in a SuspendHistoryContext object,
which contains the current document in a variable document.
For more info and advanced context, see core.executeAsModal
API, for which suspendHistory is a simple wrapper.
The callback function.
The name for the history state.
Applies trapping to a CMYK document.
Valid only when Document.mode is Constants.DocumentMode.CMYK
The trap width.
Trims the area around the image according to the type of pixels given. All sides of the image are targeted by default. Optionally, the sides may be individually specified for exclusion.
Defaults to the top left pixel color.
Optionaltop: booleanTrim the top side (default: true).
Optionalleft: booleanTrim the left side (default: true).
Optionalbottom: booleanTrim the bottom side (default: true).
Optionalright: booleanTrim the right side (default: true).
Represents a single Photoshop document that is currently open.
You can access instances of documents using one of these methods:
See
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/document/
Example
Example