2 Replies Latest reply on Jun 24, 2011 3:58 AM by JJMack

    Add a drop shadow to Text Layer

    nyxynyx

      I have tried searching around, but I cant figure out how to add a drop shadow to an existing text layer. My code is shown below...

       

      I'm using Adobe Photoshop CS5

       

       

      #target photoshop

      var inputFolder = Folder.selectDialog("Select a folder of documents to process");

      if(inputFolder) main();

      function main(){

      Count = 0;

      //This is where the output folder is created in this case its called PageNumbered

      var PathFolder = new Folder(decodeURI(inputFolder)+"/numbered");

      if (PathFolder.exists == false) PathFolder.create();

      var fileList = inputFolder.getFiles();

      for (var i = 0; i < 5; i++) {

              var file = fileList[0];


      //////////////////////////////////////////////////////////////////////////////////////

      //Change the line below to the extention of your input files ie:

      //if the imput files are tif the line should be

      // if (file instanceof File && file.name.match(/\.tif$/i)) {

        if (file instanceof File && file.name.match(/\.png$/i)) {

              open(file);


      doc = app.activeDocument;

      var startRulerUnits = preferences.rulerUnits

      app.preferences.rulerUnits = Units.PIXELS

      //Amend to suit.

      var fontSize = 14;

      var fontName = "Arial-BoldMT"; // NB: must be postscript name of font!

      // This is the colour of the text in RGB

      //Click foreground colour in Photoshop, choose your colour and read off the RGB values

      //these can then be entered below.

      var textColor = new SolidColor();

              textColor.rgb.red  = 255;

              textColor.rgb.green =255;

              textColor.rgb.blue = 255;


      var newTextLayer = doc.artLayers.add();

      newTextLayer.kind = LayerKind.TEXT;

      newTextLayer.textItem.size = fontSize;

      newTextLayer.textItem.font = fontName;

      newTextLayer.textItem.contents = ++Count;

      newTextLayer.textItem.color = textColor;

      newTextLayer.textItem.kind = TextType.PARAGRAPHTEXT;

      newTextLayer.textItem.height = fontSize;

      newTextLayer.textItem.width = doc.width;

      //The line below is the text position (X Y)  IE; 10 Pixels Right 10 Pixels Down

      newTextLayer.textItem.position = Array(0, 12);

      //  Can be RIGHTJUSTFIED LEFTJUSTIFIED CENTERJUSTIFIED

      newTextLayer.textItem.justification=Justification.CENTERJUSTIFIED;

      doc.flatten();

      var saveFile = new File(decodeURI(PathFolder) + "/" +activeDocument.name.slice(0,-4)+ "_" + (i+1) + ".png");

      //SaveForWeb(saveFile,80);

      //saveForWebPNG(saveFile);

      savePNG_2(saveFile);

      //SavePNG(saveFile);

      activeDocument.close(SaveOptions.DONOTSAVECHANGES);

      preferences.rulerUnits = startRulerUnits;

        }

      }

      }


      function SaveForWeb(saveFile,jpegQuality) {

      var sfwOptions = new ExportOptionsSaveForWeb();

         sfwOptions.format = SaveDocumentType.JPEG;

         sfwOptions.includeProfile = false;

         sfwOptions.interlaced = 0;

         sfwOptions.optimized = true;

         sfwOptions.quality = jpegQuality; //0-100

      activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

      }


      function SavePNG(saveFile){

          pngSaveOptions = new PNGSaveOptions();

          pngSaveOptions.transparency = true;

      activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);

      }


      function saveForWebPNG(saveFile)

      {

          var opts, file;

          opts = new ExportOptionsSaveForWeb();

          opts.format = SaveDocumentType.PNG;

          opts.PNG8 = false;

          opts.quality = 100;

          opts.transparency = true;

          file = new File(saveFile);

          activeDocument.exportDocument(file, ExportType.SAVEFORWEB, opts);

      }


      function savePNG_2(saveFile) {

          docExportOptions = new ExportOptionsSaveForWeb


          docExportOptions.format = SaveDocumentType.PNG; //-24 //JPEG, COMPUSERVEGIF, PNG-8, BMP

          docExportOptions.transparency = true;

          docExportOptions.blur = 0.0 ;

          docExportOptions.includeProfile = false ;

          docExportOptions.interlaced = false ;

          docExportOptions.optimized = true ;

          docExportOptions.quality = 100 ;

          docExportOptions.PNG8 = false ;


          activeDocument.exportDocument (saveFile,ExportType.SAVEFORWEB,docExportOptions) ;

          }

        • 1. Re: Add a drop shadow to Text Layer
          Muppet Mark Level 5

          You will need to the output from the scriptlistener plug-in… Layer styling is only accessible via action manager code… Recoded the basic idea for you the descriptors are 'mostly' readable so you can choose which to hard code the values and which you would like to pass as arguments…

           

          addDropShadow();
          
          function addDropShadow() {
               function cTID(s) { return app.charIDToTypeID(s); };
               function sTID(s) { return app.stringIDToTypeID(s); };
          
               var desc31 = new ActionDescriptor();
               var ref3 = new ActionReference();
               ref3.putProperty( cTID('Prpr'), cTID('Lefx') );
               ref3.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
               desc31.putReference( cTID('null'), ref3 );
               var desc32 = new ActionDescriptor();
               desc32.putUnitDouble( cTID('Scl '), cTID('#Prc'), 100.000000 );
               var desc33 = new ActionDescriptor();
               desc33.putBoolean( cTID('enab'), true );
               desc33.putEnumerated( cTID('Md  '), cTID('BlnM'), cTID('Mltp') );
               var desc34 = new ActionDescriptor();
               desc34.putDouble( cTID('Rd  '), 0.000000 );
               desc34.putDouble( cTID('Grn '), 0.000000 );
               desc34.putDouble( cTID('Bl  '), 0.000000 );
               desc33.putObject( cTID('Clr '), cTID('RGBC'), desc34 );
               desc33.putUnitDouble( cTID('Opct'), cTID('#Prc'), 75.000000 );
               desc33.putBoolean( cTID('uglg'), true );
               desc33.putUnitDouble( cTID('lagl'), cTID('#Ang'), 120.000000 );
               desc33.putUnitDouble( cTID('Dstn'), cTID('#Pxl'), 5.000000 );
               desc33.putUnitDouble( cTID('Ckmt'), cTID('#Pxl'), 0.000000 );
               desc33.putUnitDouble( cTID('blur'), cTID('#Pxl'), 5.000000 );
               desc33.putUnitDouble( cTID('Nose'), cTID('#Prc'), 0.000000 );
               desc33.putBoolean( cTID('AntA'), false );
               var desc35 = new ActionDescriptor();
               desc35.putString( cTID('Nm  '), "Linear" );
               desc33.putObject( cTID('TrnS'), cTID('ShpC'), desc35 );
               desc33.putBoolean( sTID('layerConceals'), true );
               desc32.putObject( cTID('DrSh'), cTID('DrSh'), desc33 );
               desc31.putObject( cTID('T   '), cTID('Lefx'), desc32 );
               executeAction( cTID('setd'), desc31, DialogModes.NO );
          };
          

           

          You just need make sure of your documents 'activeLayer' before you call it…

          • 2. Re: Add a drop shadow to Text Layer
            JJMack Most Valuable Participant

            I would think you could use applystyle(name) using a named style in the style palette or use the scriptlistener plugin to generate action manager code.