1 Reply Latest reply on Mar 5, 2016 8:06 AM by JJMack

    Photoshop Script Change Blend Mode

    neila73906844

      Hi Guys

      I am a totally newbie when it comes to scripts but I have an existing script that works well to add an image onto a template and then you select the blend mode and away it goes.

      Problem is that I need to select another blend mode now. I thought it would be a case of changing the blend mode within the script but doesnt work.

      I would really appreciate any help on this, Im sure its a simple fix. Its the Multiply blend mode thats been added and causing the issue.

       

      I added copied and edited the code below (not sure what it mans at all)

      Win.btnPnl.rb4.onClick = function()

              {Win.close();     

               Exe(4);

       

      as there was only 3 blend modes previously.

       

       

       

       

      Here is script

       

       

      app.displayDialogs = DialogModes.NO;

       

      var TemplateFile = File.openDialog ("Please select a template :", "*.psd");

      var DesignsFolder = Folder.selectDialog("Please select Designs folder :");

       

       

      preferences.typeUnits = TypeUnits.PIXELS;

      preferences.rulerUnits = Units.PIXELS;

       

      open(File(TemplateFile));

      var DocRef = activeDocument; 

       

      var Rectangle = DocRef.activeLayer;

      var Rectangle = DocRef.channels.getByName("PASTE HERE");

      var Selection = DocRef.selection.load(Rectangle);

      var Bound = DocRef.selection.bounds ;

       

      PosX =  Bound[0];

      PosY =  Bound[1];

      DimX =  Bound[2] - Bound[0];

      DimY =  Bound[3] - Bound[1];

       

      var DesignsList = DesignsFolder.getFiles("*.psd"| "*.jpg"| "*.jpeg");

       

      var Win = new Window('dialog', 'BendMode :');

       

          Win.size = [150,150];

          Win.btnPnl = Win.add('panel', undefined, 'Build it');

       

          Win.btnPnl.rb1 = Win.btnPnl.add('radiobutton', undefined, 'Darken');

          Win.btnPnl.rb2 = Win.btnPnl.add('radiobutton', undefined, 'Normal');

          Win.btnPnl.rb3 = Win.btnPnl.add('radiobutton', undefined, 'Lighten');

          Win.btnPnl.rb4 = Win.btnPnl.add('radiobutton', undefined, 'Multiply');

       

       

             Win.btnPnl.rb1.onClick = function()

              {Win.close();     

               Exe(1);

              }

             Win.btnPnl.rb2.onClick = function()

              {Win.close();     

               Exe(2);

              }

             Win.btnPnl.rb3.onClick = function()

              {Win.close();     

               Exe(3);

              }

             Win.btnPnl.rb4.onClick = function()

              {Win.close();     

               Exe(4);

              }

       

         

            Win.show();

       

      function Exe(Val){

       

          for(I=0; I < DesignsList.length ; I++ ){

             

              open(DesignsList[I]);

              var TempDocRef = activeDocument;

              var N = TempDocRef.name

              TempDocRef.resizeImage(DimX,DimY, undefined, undefined);

              TempDocRef.selection.selectAll();

             

              if(TempDocRef.activeLayer.isBackgroundLayer == true){

                  TempDocRef.selection.copy();

                  }else{

                      TempDocRef.selection.copy(true);

                  }

             

              TempDocRef.close(SaveOptions.DONOTSAVECHANGES);

              PasteANDSave(N);

              };

       

          function PasteANDSave(N){

              DocRef.artLayers.add();

              var Selection = DocRef.selection.load(Rectangle);

              DocRef.paste();

             

              if(Val == 1){

                  DocRef.activeLayer.blendMode  = BlendMode.DARKEN;

              }else if(Val == 2){

                  DocRef.activeLayer.blendMode  = BlendMode.NORMAL;

              }else if(Val == 3){

                  DocRef.activeLayer.blendMode  = BlendMode.LIGHTEN;

              }else if(Val == 4){

                  DocRef.activeLayer.blendMode  = BlendMode.MULTIPLY;

              }

       

              DocRef.resizeImage("1000px", DocRef.height /(DocRef.width/1050) + "px",undefined, undefined);

              var JpegOptions = new JPEGSaveOptions();

              JpegOptions.quality = 12;

              DocRef.saveAs ( new File(DesignsFolder + "/result_" + N ), JpegOptions);

                     

              DocRef.activeHistoryState = DocRef.historyStates[0] ;

          }

      }

      DocRef.close(SaveOptions.DONOTSAVECHANGES);

        • 1. Re: Photoshop Script Change Blend Mode
          JJMack Most Valuable Participant

          I see some problem area

           

          app.displayDialogs = DialogModes.NO;

           

          var TemplateFile = File.openDialog ("Please select a template :", "*.psd");

          var DesignsFolder = Folder.selectDialog("Please select Designs folder :");

           

          preferences.typeUnits = TypeUnits.PIXELS;

          preferences.rulerUnits = Units.PIXELS;

           

          open(File(TemplateFile));

          var DocRef = activeDocument;

           

          var Rectangle = DocRef.activeLayer;

          var Rectangle = DocRef.channels.getByName("PASTE HERE");

          // The above looks odd the second set of Rectangle is not effected by the fist set

          // The alpha channel can have any shape  its bounds will be a rectangle

          var Selection = DocRef.selection.load(Rectangle);

          var Bound = DocRef.selection.bounds ;

           

          PosX =  Bound[0];

          PosY =  Bound[1];

          DimX =  Bound[2] - Bound[0];

          DimY =  Bound[3] - Bound[1];

           

          //var DesignsList = DesignsFolder.getFiles("*.psd"| "*.jpg"| "*.jpeg");  // Does not do the job for me

          var DesignsList = DesignsFolder.getFiles(/\.(jpg|jpe|jpeg|psd)$/i);

           

          var Win = new Window('dialog', 'BendMode :');

           

              Win.size = [150,150];

              Win.btnPnl = Win.add('panel', undefined, 'Build it');

           

              Win.btnPnl.rb1 = Win.btnPnl.add('radiobutton', undefined, 'Darken');

              Win.btnPnl.rb2 = Win.btnPnl.add('radiobutton', undefined, 'Normal');

              Win.btnPnl.rb3 = Win.btnPnl.add('radiobutton', undefined, 'Lighten');

              Win.btnPnl.rb4 = Win.btnPnl.add('radiobutton', undefined, 'Multiply');

           

                 Win.btnPnl.rb1.onClick = function()

                  {Win.close();    

                   Exe(1);

                  }

                 Win.btnPnl.rb2.onClick = function()

                  {Win.close();    

                   Exe(2);

                  }

                 Win.btnPnl.rb3.onClick = function()

                  {Win.close();    

                   Exe(3);

                  }

                 Win.btnPnl.rb4.onClick = function()

                  {Win.close();    

                   Exe(4);

                  }

            

                Win.show();

           

          function Exe(Val){

           

              for(I=0; I < DesignsList.length ; I++ ){

                  open(DesignsList[I]);

                  var TempDocRef = activeDocument;

                  var N = TempDocRef.name

          alert("This resize will distort images that have a different aspect ratio then the alpha chanel")

                  TempDocRef.resizeImage(DimX,DimY, undefined, undefined);

                  TempDocRef.selection.selectAll();

                

                  if(TempDocRef.activeLayer.isBackgroundLayer == true){

                      TempDocRef.selection.copy();

                      }else{

                          TempDocRef.selection.copy(true);

                      }

                

                  TempDocRef.close(SaveOptions.DONOTSAVECHANGES);

                  PasteANDSave(N);

                  };

           

              function PasteANDSave(N){

                  DocRef.artLayers.add();                         // not needed paste will add a layer

          //   there may be a problem  with paste if the clipboard image has a different  color profile

          //   than the tenplate document it depends of the users Photoshop Color settings.

                  var Selection = DocRef.selection.load(Rectangle);

                  DocRef.paste();

          // You could add the selection as a layer mask to shape the pasted layer to the alpha channel shape.

                

                  if(Val == 1){

                      DocRef.activeLayer.blendMode  = BlendMode.DARKEN;

                  }else if(Val == 2){

                      DocRef.activeLayer.blendMode  = BlendMode.NORMAL;

                  }else if(Val == 3){

                      DocRef.activeLayer.blendMode  = BlendMode.LIGHTEN;

                  }else if(Val == 4){

                      DocRef.activeLayer.blendMode  = BlendMode.MULTIPLY;

                  }

           

                  DocRef.resizeImage("1000px", DocRef.height /(DocRef.width/1050) + "px",undefined, undefined);

                  var JpegOptions = new JPEGSaveOptions();

                  JpegOptions.quality = 12;                                                  // I would use quality 10 to reduce file size

                  DocRef.saveAs ( new File(DesignsFolder + "/result_" + N ), JpegOptions);   // would save files in a subfolder so addition templates could be populated

                  DocRef.activeHistoryState = DocRef.historyStates[0] ;                      //reset Template

              }

          }

          DocRef.close(SaveOptions.DONOTSAVECHANGES);                                        // do not save over the template