Adobe Photoshop CS2 – Applying a wave filter

In this section we’ll apply a wave filter to the word Hello in our document. This entails the following steps:

  • Set the document width and height to pixels and then rasterize the text object in the Text Layer.

    Note: Because text is a vector graphic and a wave filter cannot be applied to vector graphics, we must first convert the image to a bitmap. Rasterizing converts mathematically defined vector artwork to pixels. For more information on rasterizing, refer to Adobe Photoshop CS2 Help.

  • Select the area of the layer to which we want to apply the wave filter.

    Note: See “Defining the area of a selection object” on page 54 in order to understand the code within the script that accomplishes this task.

  • Apply a wave filter to the selection.

    Note: The wave is a truncated sine curve.

Defining the area of a selection object

To define the area of a selection object, we will create an array of coordinates, or points specified in pixels within the document. The array indicates the coordinates that define the outside corners of a rectangular area that begins at the top left corner of the document and extends half way across the document.

Note: You can define any number of points for a selected area. The number of coordinates determines the shape of the selection. The last coordinate defined must be the same as the first so that the area.

The array values in order are:

  • Upper left corner of the selection: 0,0
    • 0 indicates the left-most column in the document.
    • 0 indicates the top row in the document.
  • Upper right corner of the selection: theDocWidthInPixels / 2, 0
    • theDocWidthInPixels / 2 indicates the column in the middle of the document; that is, the column whose coordinate is the total number of columns in the document divided by 2.

      Note

      The value of theDocWidthInPixels is the total number of pixels that defines the document’s horizontal dimension. Columns are arranged horizontally.

    • 0 indicates the top row in the document.
  • Lower right corner: theDocWidthInPixels / 2, theDocHeightInPixels
    • theDocWidthInPixels / 2 indicates the middle of the document.
    • theDocHeightInPixels indicates the bottom row in the document; that is row whose coordinate is the total number of rows in the document.

      Note

      The value of theDocHeightInPixels is the total number of pixels that determine the vertical dimension of the document. Rows are stacked vertically.

  • Lower left corner: theDocWidthInPixels / 2, 0
    • theDocWidthInPixels / 2
    • 0
  • Upper left corner of the selection: 0,0

• To select an area and apply a wave filter to it:

  1. Type the following code into the script file HelloWorldDoc just above the commented statements that restore original preferences:
    //create new variables to contain doc width and height
    //convert inches to pixels by multiplying the number of
    inches by
    //the resolution (which equals number of pixels per inch)
    docWidthInPixels = docWidthInInches * resolution
    docHeightInPixels = docHeightInInches * resolution
    //use the rasterize method of the artLayer class
    newTextLayer.rasterize(RasterizeType.TEXTCONTENTS)
    
    //create a variable to contain the coordinate values
    //for the selection object
    selRegion = Array(Array(0, 0),
       Array(docWidthInPixels / 2, 0),
       Array(docWidthInPixels / 2, docHeightInPixels),
       Array(0, docHeightInPixels),
       Array(0, 0))
    
    //use the select method of the selection object
    //to create an object and give it the selRegion values
    //as coordinates
    docRef.selection.select(selRegion)
    
    //
    newTextLayer.applyWave(1, 1, 100, 5, 10, 100, 100,
       WaveType.SINE, UndefinedAreas.WRAPAROUND, 0)
    
  2. Save the script, and then open Adobe Photoshop CS2 and select the script from the Scripts menu (choose File > Script > HelloWorldDoc).
  3. After viewing the document in Adobe Photoshop CS2, close Adobe Photoshop CS2 without saving the document.

Note

Look up the following classes in the Adobe JavaScript Scripting Reference “Object Reference” chapter to see if you understand how you used them in this script:

  • ArtLayer
    • Rasterize() method. Notice that the RasterizeType.TEXTCONTENTS argument uses the RasterizeType constant. Constants are always depicted in uppercase letters in Adobe Photoshop CS2 JavaScripts.
    • applyWave() method