UXP Toolkit
    Preparing search index...

    Represents a single Photoshop document that is currently open.

    You can access instances of documents using one of these methods:

    const {app, constants} = require('photoshop');
    // The currently active document from the Photoshop object
    const currentDocument = app.activeDocument;
    // Choose one of the open documents from the Photoshop object
    const secondDocument = app.documents[1];
    // You can also create an instance of a document via a UXP File entry
    let fileEntry = require('uxp').storage.localFileSystem.getFileForOpening();
    const newDocument = await app.open('/project.psd');
    Index

    Properties

    saveAs: {
        bmp: (
            entry: File,
            saveOptions?: BMPSaveOptions,
            asCopy?: boolean,
        ) => Promise<void>;
        gif: (
            entry: File,
            saveOptions?: GIFSaveOptions,
            asCopy?: boolean,
        ) => Promise<void>;
        jpg: (
            entry: File,
            saveOptions?: JPEGSaveOptions,
            asCopy?: boolean,
        ) => Promise<void>;
        png: (
            entry: File,
            saveOptions?: PNGSaveOptions,
            asCopy?: boolean,
        ) => Promise<void>;
        psb: (
            entry: File,
            saveOptions?: PhotoshopSaveOptions,
            asCopy?: boolean,
        ) => Promise<void>;
        psd: (
            entry: File,
            saveOptions?: PhotoshopSaveOptions,
            asCopy?: boolean,
        ) => Promise<void>;
    }

    Save the document to a desired file type.

    For operations that require a UXP File token, use the UXP storage APIs to generate one.

    Type Declaration

    • bmp: (entry: File, saveOptions?: BMPSaveOptions, asCopy?: boolean) => Promise<void>

      Save the document as a BMP file.

      23.0

    • gif: (entry: File, saveOptions?: GIFSaveOptions, asCopy?: boolean) => Promise<void>

      Save the document as a GIF file.

      23.0

    • jpg: (entry: File, saveOptions?: JPEGSaveOptions, asCopy?: boolean) => Promise<void>

      Save the document as a JPG file.

      23.0

    • png: (entry: File, saveOptions?: PNGSaveOptions, asCopy?: boolean) => Promise<void>

      Save the document as a PNG file.

      23.0

    • psb: (
          entry: File,
          saveOptions?: PhotoshopSaveOptions,
          asCopy?: boolean,
      ) => Promise<void>

      Save the document as a PSB file.

      23.0

    • psd: (
          entry: File,
          saveOptions?: PhotoshopSaveOptions,
          asCopy?: boolean,
      ) => Promise<void>

      Save the document as a PSD file.

      23.0

    let entry = await require('uxp').storage.localFileSystem.getFileForSaving("target.psd");
    document.saveAs.psd(entry);
    // Save as a Copy (High JPG quality)
    document.saveAs.jpg(entryJpg, {quality: 12}, true);
    // Save a PSB, with some options:
    document.saveAs.psb(entryPsb, {embedColorProfile: true});

    23.0

    selection: Selection

    The object containing the document's currently active selection.

    Accessors

    Methods

    • 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.

      Parameters

      Returns Promise<void | Channel | Document>

      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);

      24.5

    • 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"

      Parameters

      • destinationProfile: string

        The profile name or working space.

      • intent: Intent

        The rendering intent.

      • OptionalblackPointCompensation: boolean

        Whether to use black point compensation.

      • Optionaldither: boolean

        Whether to use dithering.

      Returns Promise<void>

    • Duplicates given layer(s), creating all copies above the top most one in layer stack, and returns the newly created layers.

      Parameters

      • layers: Layer[]

        The array of layers to duplicate.

      • OptionaltargetDocument: Document

        If specified, send the duplicates to a different document.

      Returns Promise<Layer[]>

      // duplicate some layers
      const layerCopies = await document.duplicateLayers([layer1, layer3])
      layerCopies.forEach((layer) => { layer.blendMode = 'multiply' })
      // ...to another document
      const finalDoc = await photoshop.open('~/path/to/collated/image.psd')
      await document.duplicateLayers([logo1, textLayer1], finalDoc)
      await finalDoc.close(SaveOptions.SAVECHANGES)

      23.0

    • Applies generative upscaling to the currently selected layer(s) using AI-powered upscaling technology.

      Parameters

      Returns Promise<void>

      // Upscale using Firefly model with default options (2x scale)
      await document.generativeUpscale(constants.GenerativeUpscaleModel.FIREFLY);

      // Upscale using Firefly model with 4x scale
      const doc4x = await document.generativeUpscale(constants.GenerativeUpscaleModel.FIREFLY, { scale: 4 });

      27.2

    • Changes the size of the image by scaling the dimensions to meet the targeted number of pixels.

      Parameters

      • Optionalwidth: number

        Numeric value of new width in pixels.

      • Optionalheight: number

        Numeric value of new height in pixels.

      • Optionalresolution: number

        Image resolution in pixels per inch (ppi).

      • OptionalresampleMethod: ResampleMethod

        Method used during image interpolation.

      • Optionalamount: number

        Numeric value that controls the amount of noise value when using preserve details 0..100.

      Returns Promise<void>

      await document.resizeImage(800, 600)
      

      23.0

    • 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.

      Parameters

      • callback: (e: SuspendHistoryContext) => void

        The callback function.

      • historyStateName: string

        The name for the history state.

      Returns Promise<void>

      app.activeDocument.suspendHistory(async (context) => {
      // context.document below is, in this case, `app.activeDocument`
      context.document.activeLayers[0].name = "Changed name";
      });

      23.0

    • 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.

      Parameters

      • trimType: TrimType

        Defaults to the top left pixel color.

      • Optionaltop: boolean

        Trim the top side (default: true).

      • Optionalleft: boolean

        Trim the left side (default: true).

      • Optionalbottom: boolean

        Trim the bottom side (default: true).

      • Optionalright: boolean

        Trim the right side (default: true).

      Returns Promise<void>

      // trim transparent pixels from only the bottom of the image
      app.activeDocument.trim(constants.TrimType.TRANSPARENT, false, false, true, false);

      23.0