15 Replies Latest reply: Dec 2, 2012 9:39 AM by clayevans RSS

    open multiple imgs in stack and align in defined pattern

    clayevans

      hello everyone.

       

      i know to handle ps but related to scripting in ps i am a real noob. because of that i would like to post what fuctionality the script should have and i am thankfull for every hint or point to start.

      The attachment shows the pattern  how the images have to be aligned.

       

      1. open a new document with an given size (this is done manually, got a .psd here with adjustmentlayers)

       

      2. import six images (lets call them from A to F) in the layerstack (optionally unter all the adjustment layers)

      3. align the six images as the attachment shows: image A goes on position 1, image B goes on position 2 and so on.

      4. save image as specific format (.tif)

       

      I hope some of you can help me with good starting points, i dont expect a full script, but some good outlines and keywords would be superb,

      thank you

       

       

      sample.jpg

        • 1. Re: open multiple imgs in stack and align in defined pattern
          Michael L Hale Community Member

          Some questions. Will the images always be in the same place? And in alphabetical order? In other words how with the script be able to find the images to open and what order? Will there be more than 6 images to be processed at one time?

           

          And have you had a look at data driven graphic in the Photoshop help file. It could be you don't need a script at all.

           

          A rough outline would be to open a file, dupe the activeLayer to the template doc, then translate the layer into place. Loop until all 6 images are placed.

          • 2. Re: open multiple imgs in stack and align in defined pattern
            Paul Riggott Community Member

            Another option would be to create a template PSD, use File - Place to get all the images in and in the correct places, then these Smart Objects could be replaced.

            • 3. Re: open multiple imgs in stack and align in defined pattern
              clayevans Community Member

              @ Michael L Hale

               

               

              unfortunately i cant edit my post. you have some good questions. i will try to answer them and some mor detaild info:

               

               

              a) 1 set contains the six images (these are the six images i explained in my first post), i have to process about 500 sets.

              b) all six images eacht set have the same name (A.tif to F.tif)

              c) all six images of each set have the same size, in general there are to sizes as shown in the red picture, so every A.tif has always the same rectangular format (B.tif a corresponding square format)(remember A.tif = postion 1, B.tif = postion 2)

              d) a open dialog to select multiple files would be ok. "select multiple files" means: i pick them by myself

              e) 1 set will not contain more or less then six images, so there have to be always processed six images a time

               

               

              - i will refer to the data driven graphic topic, thank you

              - maybe is it possible to gibt your outline a bit of detail with the new information above?

               

               

              @ Paul Riggott

              i will try your point, not sure if it works for a big amount of images but maybe i just dont fully understand it at the moment. as i said i will have look at your point, thank you.

              • 4. Re: open multiple imgs in stack and align in defined pattern
                JJMack Community Member

                That would be very easy to do using the scripts in my Photoshop Photo Collage Toolkit.  All ypu need do s to create a simple PSD template. The template would consist of a Background layer. Six Alpha channeles names Image 1, Image 2, ..., Image 6. And the adjustment layers you want applied to you images.  Once you have that template PSD file all you need do is to run one of the populating scripts in the toolkit. Point it ate your template psd and at your source image folder.  There are option to add image layer styles and stamp file names on images. Image are populated in order. You can add a prefix the file name so image file sort in the order you want the images populated.  There are scripts the populate template interactively, automatically and even batching is possible.

                 

                A video of a template being populated http://www.mouseprints.net/old/dpr/PopulateCollage.html

                 

                Documentation: http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html

                • 5. Re: open multiple imgs in stack and align in defined pattern
                  Paul Riggott Community Member

                  As an example create a PSD with all your images, but add them in using File - Place, this will create Smart Objects.

                  Once you have done this, this PSD could then be a template.

                  The following Script would the replace all the Smart Objects with the first six documents selected in Bridge....

                   

                   

                  main();
                  function main(){
                  if(!documents.length) return;
                  var SOs = getSOPlusIDs();
                  //reverse the layer order if required
                  //SOs.reverse();
                  if(SOs.length != 6){
                      alert("There should be 6 Smart Objects and you have " + SOs.length);
                      return;
                      }
                  if (!BridgeTalk.isRunning( "bridge" ) ) {
                      alert("You need to select your files in Bridge!");
                      return;
                      }
                  var bridgeFiles = GetFilesFromBridge();
                  if(bridgeFiles.length < 6 ) {
                      alert("You need to select at least 6 files!\rOnly " + bridgeFiles.length + " files selected!");
                      return;
                      }
                  for(var a in SOs){
                      selectLayerById(Number(SOs[a][0]));
                      replaceSO(bridgeFiles[a].toString());
                      }
                  }
                  function replaceSO(SO){ 
                  var desc = new ActionDescriptor(); 
                  desc.putPath( charIDToTypeID( "null" ), new File( SO ) ); 
                  executeAction( stringIDToTypeID( "placedLayerReplaceContents" ), desc, DialogModes.NO ); 
                  };
                  function selectLayerById(ID, add) {
                      add = (add == undefined)  ? add = false : add;
                   var ref = new ActionReference();
                   ref.putIdentifier(charIDToTypeID('Lyr '), ID);
                   var desc = new ActionDescriptor();
                   desc.putReference(charIDToTypeID('null'), ref);
                   if (add) {
                    desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
                   }
                   desc.putBoolean(charIDToTypeID('MkVs'), false);
                   executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
                  };
                  function getSOPlusIDs(){ 
                     var ref = new ActionReference(); 
                     ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
                     var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1; 
                     var Names=[];
                  try{
                      activeDocument.backgroundLayer;
                  var i = 0; }catch(e){ var i = 1; };
                     for(i;i<count;i++){ 
                         if(i == 0) continue;
                          ref = new ActionReference(); 
                          ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
                          var desc = executeActionGet(ref);
                          var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
                          var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
                          if(layerName.match(/^<\/Layer group/) ) continue;
                          var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
                          var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
                          if( desc.hasKey( stringIDToTypeID( 'smartObject' ) ) ) Names.push([[Id],[layerName]]);
                     }; 
                  return Names;
                  };
                  function GetFilesFromBridge() {
                  function script(){
                  var fL = app.document.selections;
                  var tF=[];
                  for(var a in fL){
                      if(fL[a].type =='file'){
                          tF.push(new File(encodeURI(fL[a].spec.fsName)));
                          }
                      }
                  return tF.toSource();
                  }
                   var fileList;
                    var bt = new BridgeTalk();
                    bt.target = "bridge";
                          bt.body = "var ftn = " + script.toSource() + "; ftn();";
                    bt.onResult = function( inBT ) { fileList = eval( inBT.body ); }
                    bt.onError = function( inBT ) { fileList = new Array(); }
                    bt.send(8);
                    bt.pump();
                   if ( undefined == fileList ) fileList = new Array();
                   return fileList; 
                  };
                  
                   
                  
                  • 6. Re: open multiple imgs in stack and align in defined pattern
                    clayevans Community Member

                    thank you for your info, i´ve watch your page, seems really this is what i could need. maybe your tools is a bit overpowered for my simple action but i will give it a try for sure, thank you!

                    • 7. Re: open multiple imgs in stack and align in defined pattern
                      clayevans Community Member

                      i´ve tried your script, thank you for that!

                      it works nicely, but allow me to make a comment, i am no big fan of bridge

                      could you give me a hint if it is possible to change that to a style like: "sys dialog opens, select a folder" and hit "open" ?

                      as newbie on real scripting with .jsx my simple task seems quite complex.

                       

                      @all, this forum is really awesome, thank you all!

                      • 8. Re: open multiple imgs in stack and align in defined pattern
                        Paul Riggott Community Member

                        This will use the first 6 images in the selected folder ....

                         

                         

                        main();
                        function main(){
                        if(!documents.length) return;
                        var SOs = getSOPlusIDs();
                        //reverse the layer order if required
                        //SOs.reverse();
                        if(SOs.length != 6){
                            alert("There should be 6 Smart Objects and you have " + SOs.length);
                            return;
                            }
                        var folder = Folder.selectDialog( "Please select source folder");
                        if(folder == null) return;
                        //file types to look for
                        var fileList = folder.getFiles(/\.(jpg|tif|psd|png)$/i);
                        if(fileList.length < 6 ) {
                            alert("You need to select at least 6 files!\rOnly " + fileList.length + " files selected!");
                            return;
                            }
                        for(var a in SOs){
                            selectLayerById(Number(SOs[a][0]));
                            replaceSO(fileList[a].toString());
                            }
                        }
                        function replaceSO(SO){ 
                        var desc = new ActionDescriptor(); 
                        desc.putPath( charIDToTypeID( "null" ), new File( SO ) ); 
                        executeAction( stringIDToTypeID( "placedLayerReplaceContents" ), desc, DialogModes.NO ); 
                        };
                        function selectLayerById(ID, add) {
                            add = (add == undefined)  ? add = false : add;
                         var ref = new ActionReference();
                         ref.putIdentifier(charIDToTypeID('Lyr '), ID);
                         var desc = new ActionDescriptor();
                         desc.putReference(charIDToTypeID('null'), ref);
                         if (add) {
                          desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
                         }
                         desc.putBoolean(charIDToTypeID('MkVs'), false);
                         executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
                        };
                        function getSOPlusIDs(){ 
                           var ref = new ActionReference(); 
                           ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
                           var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1; 
                           var Names=[];
                        try{
                            activeDocument.backgroundLayer;
                        var i = 0; }catch(e){ var i = 1; };
                           for(i;i<count;i++){ 
                               if(i == 0) continue;
                                ref = new ActionReference(); 
                                ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
                                var desc = executeActionGet(ref);
                                var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
                                var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
                                if(layerName.match(/^<\/Layer group/) ) continue;
                                var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
                                var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
                                if( desc.hasKey( stringIDToTypeID( 'smartObject' ) ) ) Names.push([[Id],[layerName]]);
                           }; 
                        return Names;
                        };
                        
                         
                        
                        • 9. Re: open multiple imgs in stack and align in defined pattern
                          JJMack Community Member

                          The template you need is simply a white background and six Alpha channels name Image 1 Image 2 Image 3 Image 4 Image 5 Image 6.

                          • 10. Re: open multiple imgs in stack and align in defined pattern
                            clayevans Community Member

                            thats what i need paul, small and fast, thank you!

                            • 11. Re: open multiple imgs in stack and align in defined pattern
                              clayevans Community Member

                              hello again.

                               

                              i have modified the script from paul a little bit.

                               

                              1. first i set a generall folder for faster navigation: var folder = Folder.selectDialog( "Please select source folder", "desired folder destination goes here");

                               

                              2. after processing the images i would like to save them:

                               

                              var file = new File( );

                              file.saveDlg("interior", "*.tif" );

                               

                              Now my questions,

                               

                              how can i tell photoshop " use the path to save the .tif were i imported the images before" ? do i have to work with that "folder" var?

                               

                              thank you

                              • 12. Re: open multiple imgs in stack and align in defined pattern
                                Paul Riggott Community Member

                                This should save a tif file to the selected folder...

                                 

                                 

                                main();
                                function main(){
                                if(!documents.length) return;
                                var SOs = getSOPlusIDs();
                                //reverse the layer order if required
                                //SOs.reverse();
                                if(SOs.length != 6){
                                    alert("There should be 6 Smart Objects and you have " + SOs.length);
                                    return;
                                    }
                                var folder = Folder.selectDialog( "Please select source folder");
                                if(folder == null) return;
                                //file types to look for
                                var fileList = folder.getFiles(/\.(jpg|tif|psd|png)$/i);
                                if(fileList.length < 6 ) {
                                    alert("You need to select at least 6 files!\rOnly " + fileList.length + " files selected!");
                                    return;
                                    }
                                for(var a in SOs){
                                    selectLayerById(Number(SOs[a][0]));
                                    replaceSO(fileList[a].toString());
                                    }
                                var saveFile = File(folder + "/Interior.tif");
                                SaveTIFF(saveFile);
                                }
                                function replaceSO(SO){ 
                                var desc = new ActionDescriptor(); 
                                desc.putPath( charIDToTypeID( "null" ), new File( SO ) ); 
                                executeAction( stringIDToTypeID( "placedLayerReplaceContents" ), desc, DialogModes.NO ); 
                                };
                                function selectLayerById(ID, add) {
                                    add = (add == undefined)  ? add = false : add;
                                 var ref = new ActionReference();
                                 ref.putIdentifier(charIDToTypeID('Lyr '), ID);
                                 var desc = new ActionDescriptor();
                                 desc.putReference(charIDToTypeID('null'), ref);
                                 if (add) {
                                  desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));
                                 }
                                 desc.putBoolean(charIDToTypeID('MkVs'), false);
                                 executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
                                };
                                function getSOPlusIDs(){ 
                                   var ref = new ActionReference(); 
                                   ref.putEnumerated( charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); 
                                   var count = executeActionGet(ref).getInteger(charIDToTypeID('NmbL')) +1; 
                                   var Names=[];
                                try{
                                    activeDocument.backgroundLayer;
                                var i = 0; }catch(e){ var i = 1; };
                                   for(i;i<count;i++){ 
                                       if(i == 0) continue;
                                        ref = new ActionReference(); 
                                        ref.putIndex( charIDToTypeID( 'Lyr ' ), i );
                                        var desc = executeActionGet(ref);
                                        var layerName = desc.getString(charIDToTypeID( 'Nm  ' ));
                                        var Id = desc.getInteger(stringIDToTypeID( 'layerID' ));
                                        if(layerName.match(/^<\/Layer group/) ) continue;
                                        var layerType = typeIDToStringID(desc.getEnumerationValue( stringIDToTypeID( 'layerSection' )));
                                        var isLayerSet =( layerType == 'layerSectionContent') ? false:true;
                                        if( desc.hasKey( stringIDToTypeID( 'smartObject' ) ) ) Names.push([[Id],[layerName]]);
                                   }; 
                                return Names;
                                };
                                function SaveTIFF(saveFile){
                                tiffSaveOptions = new TiffSaveOptions(); 
                                tiffSaveOptions.embedColorProfile = true; 
                                tiffSaveOptions.alphaChannels = true; 
                                tiffSaveOptions.layers = true;
                                tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW; 
                                activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE); 
                                }
                                
                                 
                                
                                • 13. Re: open multiple imgs in stack and align in defined pattern
                                  clayevans Community Member

                                  hello!

                                   

                                  tested the modificiation an works as needed, thank you!

                                  as i play around i cam up with this option:

                                   

                                  i have a working path tha looks like L:\1\2\3\4\5\6\7\8

                                   

                                  8: the folder were these six images in. at the moment the file is saved as whatever.tif in there

                                   

                                  is there a way to save the image always as 7.tif ?  maybe sounds strange but that would be handy.

                                  at the moment i play with this var saveFile = File(folder+"/.tif"); but i thing i need a for loop to kill the most of the L:\1\2\3\4\5\6\7\8  construction?!

                                  the L:\1\2\3\4\5\6\7\8 is always the same so i always the the name on position 7

                                  • 14. Re: open multiple imgs in stack and align in defined pattern
                                    Paul Riggott Community Member

                                    Sorry but I am not clear on what you want, does this example help?

                                     

                                     

                                    var folder = Folder.selectDialog( "Please select source folder");
                                    var saveFile = File(folder + "/7.tif");
                                    //this will save in selected folder with the name of 7.tif
                                    alert(decodeURI(saveFile));
                                    //this will save as folder name.tif in selected folder
                                    var saveFile = File(folder + "/" + folder.name + ".tif");
                                    alert(decodeURI(saveFile));
                                    //this will save as folder name.tiff in the parent folder
                                    var saveFile = File(folder.parent + "/" + folder.name + ".tif");
                                    alert(decodeURI(saveFile));
                                    
                                    
                                    • 15. Re: open multiple imgs in stack and align in defined pattern
                                      clayevans Community Member

                                      hey paul, thank you for your  fast reply!

                                      your ideas helped me alot!

                                      i´ve modified it, so this is finally what i need: var saveFile = File(folder +"/"+ folder.parent.name + ".tif");

                                      simple task if you know the syntax as i can see