0 Replies Latest reply: Jan 31, 2011 4:36 PM by retouchingguy RSS

    Script - To add watermark text with more than 1 line / font size

    retouchingguy Community Member

      Hi everyone, I've managed to find a cool script that adds a border and some text (if you want it - http://www.oblius.com/projects/photoborder/)

       

      This results in the following -

      1.jpg

      What I really need is to change the script so I can have 2 lines, centered, the second line in a smaller font, like this:

      2.jpg

       

      Any help very appreciated, I know this will be really easy for anyone with script experience (its my 1st day using them!)

       

       

      Script is:

       

      /* Customizable variables */

       

      // Outer border settings
      outerBorderThickness = 10;                     // Adds to each side (left, right, top,

       

      bottom)
      outerBorderColor = new SolidColor();        // RGB Outer Border Color (see next 3 lines)
      outerBorderColor.rgb.red = 255;                // Red value of outer border
      outerBorderColor.rgb.green = 255;                // Green value
      outerBorderColor.rgb.blue = 255;                // Blue value

       

      // Inner border settings
      innerBorderThickness = 0;                    // **Must be smaller than or equal to

       

      outer border**
      innerBorderOpacity = 75.0;                    // Percent value opacity for inner

       

      border
      innerBorderColor = new SolidColor();        // RGB Inner Border Color (see next 3 lines)
      innerBorderColor.rgb.red = 255;                // Red value of outer border
      innerBorderColor.rgb.green = 255;            // Green value
      innerBorderColor.rgb.blue = 255;            // Blue value

       

      // Signature
      signatureText = "John + Jane www.Sabrina.co.nz";    // Text to place as signature
      signatureOffsetX = 370                        // From RIGHT edge of document (tweak

       

      these after setting font/size/text etc)
      signatureOffsetY = 46                        // From BOTTOM edge of document (tweak

       

      these after setting font/size/text etc)
      signatureFont = "Verdana";                     // PostScript font name for signature
      signatureFontSize = 5.0;                     // Font size in Points
      signatureOpacity = 100.0                        // Opacity for signature
      signatureAA = AntiAlias.NONE;                 // Anti-alias mode (options: NONE, CRISP,

       

      SHARP, etc - same as palette)
      signatureColor = new SolidColor();            // RGB Signature Color (see next 3 lines)
      signatureColor.rgb.red = 255;                // Red value
      signatureColor.rgb.green = 255;                // Green value
      signatureColor.rgb.blue = 255;                // Blue value

       

      /* End Customizable Variables */

       


      /*************************************************************
      *                                                  

       

               *
      *                        BEGIN SCRIPT                      

       

      *
      *                                                  

       

               *
      **************************************************************/

       


      // Open sample file if no document is opened.
      if (!app.documents.length > 0) {   
          var fileName = app.path.toString() + "/Samples/Dune.tif";
          var docRef = open( File(fileName) );
      }

       

      // Save old units and set to px
      oldUnits = app.preferences.rulerUnits;
      app.preferences.rulerUnits = Units.PIXELS;

       

      // Save original document size
      oldWidth = app.activeDocument.width;
      oldHeight = app.activeDocument.height;

       

      // Resize canvas to make room for outer border
      newWidth = app.activeDocument.width + (outerBorderThickness*2);
      newHeight = app.activeDocument.height + (outerBorderThickness*2);
      app.activeDocument.resizeCanvas(newWidth, newHeight, AnchorPosition.MIDDLECENTER);

       

      // Create a layer for the outer border and make it active
      var outerBorderLayer = app.activeDocument.artLayers.add();
      outerBorderLayer.name = "Black Outer Border";
      outerBorderLayer.blendMode = BlendMode.NORMAL;
      app.activeDocument.activeLayer = app.activeDocument.layers["Black Outer Border"];

       

      // Select the original image area
      selectionBounds = new Array
      (
          new Array(outerBorderThickness, outerBorderThickness),
          new Array(oldWidth + outerBorderThickness, outerBorderThickness),
          new Array(oldWidth + outerBorderThickness, oldHeight + outerBorderThickness),
          new Array(outerBorderThickness, oldHeight + outerBorderThickness)
      );
      app.activeDocument.selection.select(selectionBounds, SelectionType.REPLACE);

       

      // Fill the outer border area
      app.activeDocument.selection.invert();
      app.activeDocument.selection.fill(outerBorderColor);

       

      // Create the inner border layer and make it active
      var innerBorderLayer = app.activeDocument.artLayers.add();
      innerBorderLayer.name = "White Inner Border";
      innerBorderLayer.blendMode = BlendMode.NORMAL;
      innerBorderLayer.opacity = innerBorderOpacity;
      app.activeDocument.activeLayer = app.activeDocument.layers["White Inner Border"];

       

      // Fill the inner border
      app.activeDocument.selection.invert();
      app.activeDocument.selection.expand(innerBorderThickness);
      app.activeDocument.selection.fill(innerBorderColor);
      app.activeDocument.selection.contract(innerBorderThickness);
      app.activeDocument.selection.clear();

       

      // Deselect
      app.activeDocument.selection.deselect();

       

      // Create a text layer
      var signatureLayer = app.activeDocument.artLayers.add();
      signatureLayer.name = "Signature";
      signatureLayer.kind = LayerKind.TEXT;
      signatureLayer.opacity = signatureOpacity;
      signatureLayer.blendMode = BlendMode.NORMAL;
      app.activeDocument.activeLayer = app.activeDocument.layers["Signature"];

       

      // Add signature to text layer and position it
      signatureLayer.textItem.contents = signatureText;
      signatureLayer.textItem.font = signatureFont;
      signatureLayer.textItem.size = signatureFontSize;
      signatureLayer.textItem.color = signatureColor;
      signatureLayer.textItem.antiAliasMethod = signatureAA;
      txtPos = new Array((newWidth - signatureOffsetX), (newHeight - signatureOffsetY));
      signatureLayer.textItem.position = txtPos;

       

      // Restore the original ruler units
      app.preferences.rulerUnits = oldUnits;

       

      // Clear up memory
      outerBorderThickness = null;
      outerBorderColor = null;
      innerBorderThickness = null;
      innerBorderColor = null;
      innerBorderOpacity = null;
      signatureText = null;
      signatureOffsetX = null;
      signatureOffsetY = null;
      signatureOpacity = null;
      signatureFont = null;
      signatureFontSize = null;
      signatureOpacity = null;
      signatureAA = null;
      signatureColor = null;
      selectionBounds = null;
      newWidth = null;
      newHeight = null;
      oldWidth = null;
      oldHeight = null;
      oldUnits = null;
      layerRef = null;
      signatureLayer = null;

       

      // EOF