16 Replies Latest reply on Feb 7, 2018 11:23 PM by c.pfaffenbichler

    Place images to a specific spot in a template

    Melissa Moulden

      I am trying to create an action that will drop images into a specific spot in another document and save it with a certain file name. After the first image is dropped in and saved, I want my next image to do the same and so on. I have all my images cropped to the correct ratio and being pulled from a folder on my desktop. I have my template open in Photoshop where I want my images from that folder to be dropped into. Is this possible?

       

      Any help is greatly appreciated!!

       

      Melissa

        • 1. Re: Place images to a specific spot in a template
          JJMack Most Valuable Participant

          Melissa

          What you want to do can be done but it is complex and actions have some limitations and can not use logic without using a script or two. File saving  can be tricky for an action will always save the same file name or use the current document name saved either overwriting the file or saving it to some other particular folder. Action that populate a template can be created but it will always populate the same number of images because an action can not use logic to find out how many spots there are to populate. There are different ways to drop an image into the active document you can paste into an area or just past in the image in as a new layer.  You can also Place images in as smart objects. Each method has some advantages and disadvantages. Layers can also be aligned with selections and layers can be transformed in size.  Your best off creating rule for creating a template and have a plan as to how your going to populate these templates that follow your rules. To protect the template from alteration you may want to dupe the template close the original and work on the duped version. When you dupe the template you can give the dupe a name if you do not name it the new document will have the same name with copy appended.

           

          Scripting is more powerful then Action but they are programs that are written in a scripting language. Photoshop supports three languages. VBS, Applescript and Javascript. Only Javascript is supported on both the MAC and PC platforms.  Even using Javascript you may need to code the script to work on both platforms for I'm sure there are some differences in the OS and file system the may need special handling to work on both platform.  From you description of you work-flow it is hard to tell exactly what you are doing.   If you trying simple create a photo Collage.  You may want to have a look at my free Package for Photoshop called "Photo Collage Toolkit" . I have been told this package works on a MAC but I created it and tested it on widows and got it To work with CS2, CS3, CS4 and CS5.

          .

          Photo Collage Toolkit UPDATED Sept 24, 2011 added a script to replace a Populated Layered Collage Smart Object Image with an other image with resizing.

          Photoshop scripting is powerful and I believe this package demonstrates this.

          The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.

          There are eight scripts in this package they provide the following functions:

          1. TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
          2. CollageTemplateBuilder.jsx - Can build Templates compatible with this toolkit's scripts.
          3. LayerToAlphaChan.jsx - Used to convert a Prototype Image Layer stack into a template document.
          4. InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
          5. ReplaceCollageImage.jsx - use to replace a populated collage image Smart Object layer with an other image correctly resized and positioned.
          6. PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
          7. BatchOneImageCollage.jsx - Used to Automatically Batch Populate Collage templates that only have one image inserted. The Collage or Image may be stamped with text.
          8. BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.

          Note: Rags Gardner www.rags-int-inc.com Photoshop Collage Template Builder script Copyright (c) 2006 builds layered Photo Collage Template psd files. Rags's has given me permission to include a modified version of his script in my package. The modification converts Rags's layered image template document into a flattened template compatible with Photoshop "Photo Collage Toolkit" package. There is also an option that will instead create a layered image stack like Rags's templates are these are also produced if you attempt to create a template with more then 53 images.

          Photoshop only supports up to 53 Alpha channels therefore with its design the Photo Collage Toolkit can only support collages with 1 to 53 images. I do not feel this is a big limitation for if you put 53 3:2 aspect ratio images on a large 16" x 20" paper they would need to be less then 1.9" x 2.86" in size if you wanted a frame around each and less then .95" x 1.43" on a 8" x 10" year book page size.

          While the maximum number of images in a collage is 53 you can actually create larger collages by populating a large number of images into several collages and then populate yet an other collage template with these populated collages. Each will be placed into the collage of collages as a single smart object layer. You may want to save the populates PSD file as Jpeg files first to cut down on the overhead of having large PSD file smart object layers in the collage of collages.

          Documentation and Examples


          • 2. Re: Place images to a specific spot in a template
            c.pfaffenbichler Level 9

            Personally I would prefer to use a template with a Smart Object in such a case and Replace Contents.

             

            What formats are the images to be placed, in which format what do you want the layered files saved, where to and with what names exactly?

            • 3. Re: Place images to a specific spot in a template
              c.pfaffenbichler Level 9

              Recently I’ve done something similar, so I could adapt that.

              On the lower left are the files that were selected in the Script’s dialog (all the same size, though), on the lower right are the resultant images, top center ist the template document with the Smart Object selected.

              switchSOPsdScr.jpg

              If you want to give it a try, paste the following text into a new file in ExtendScript Toolkit (part of Photoshop’s installation, /Applications/Utilities/Adobe Utilities-CS5/ExtendScript Toolkit CS5) and save it as a jsx-file into Photoshop’s Presets/Scripts-folder.

               

              // replace smart object’s content and save psd;
              // 2011, use it at your own risk;
              #target photoshop
              if (app.documents.length > 0) {
              var myDocument = app.activeDocument;
              var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];
              var thePath = myDocument.path;
              var theLayer = myDocument.activeLayer;
              // psd options;
              psdOpts = new PhotoshopSaveOptions();
              psdOpts.embedColorProfile = true;
              psdOpts.alphaChannels = true;
              psdOpts.layers = true;
              psdOpts.spotColors = true;
              // check if layer is smart object;
              if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}
              else {
              // select files;
              if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.tif", true)} 
              else {var theFiles = File.openDialog ("please select files", getFiles, true)};
              if (theFiles) {
              // work through the array;
                        for (var m = 0; m < theFiles.length; m++) {
              // replace smart object;
                                  theLayer = replaceContents (theFiles[m]);
                                  var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
              //save jpg;
                                  myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);
                                  }
                        }
              }
              };
              ////// get psds, tifs and jpgs from files //////
              function getFiles (theFile) {
                   if (theFile.name.match(/\.(psd|tif)$/i)) {
                        return true
                        };
                   };
              ////// replace contents //////
              function replaceContents (newFile) {
              // =======================================================
              var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
                  var desc3 = new ActionDescriptor();
                  var idnull = charIDToTypeID( "null" );
                  desc3.putPath( idnull, new File( newFile ) );
                  var idPgNm = charIDToTypeID( "PgNm" );
                  desc3.putInteger( idPgNm, 1 );
              executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );
              return app.activeDocument.activeLayer
              };
              
              • 4. Re: Place images to a specific spot in a template
                JJMack Most Valuable Participant

                When replacing contents you will have to resize the replaced contents if the replacement image is not the same size and aspect ratio as the smart object contends being replace. There is a transform associated with a smart object layer.  The original smart object layer has a transform associated with it and that transform will be applied to the replacement image.  In fact if you dupe the smart object layer not using new smart object via copy. Just a strait layer dupe you can have several layers all containing the single smart object with each layer having its own transform which locates its position and size. Replacing the content of any of those layers smart object changes the image on all the layers.  For a this type or collage to work correctly the original smart object image and the replacement need to be the same size.  I use Place and smart Object in my Photo Collage Toolkit.   I like to support any size image the only important thing is an image aspect ratios should closely match the aspect ratio of the template image aspect ratio.  They don't have to be same aspect ratio the scripts will fit all image into place but the apparent crop can adversely effect image composition.  Being they are smart objects they can be tweak by retransforming the placed image placement and size.

                • 5. Re: Place images to a specific spot in a template
                  c.pfaffenbichler Level 9

                  Nice explanation for the OP.

                  And the point you made in post 1 about integrating Scripts into Actions for the steps where Actions alone would fall short is also a valid one – but if in this case the names of the selected file is to be used for saving the new file it might be inconvenient if the selection and the saving would have to be done at two separate points in the Action.

                  • 6. Re: Place images to a specific spot in a template
                    JJMack Most Valuable Participant

                    Yes with actions you have few options when it come to file nameing.  Scripting is the way to go. 

                    • 7. Re: Place images to a specific spot in a template
                      SarahFaithMorris1600 Level 1

                      I can't figure out how to get this script to be able to open a folder.  When I run it , it's only letting me select PSDs on my desktop.  I'd like to be able to select files within a certain folder.  Can I change something to make it stop ghosting out folders in the opendialog command?

                      • 8. Re: Place images to a specific spot in a template
                        c.pfaffenbichler Level 9

                        On a Mac replace

                             if (theFile.name.match(/\.(psd|tif)$/i)) {

                        with

                             if (theFile.name.match(/\.(psd|tif)$/i) != null || theFile.constructor.name == "Folder") {

                        • 9. Re: Place images to a specific spot in a template
                          SarahFaithMorris1600 Level 1

                          Awesome, it works now.  I also modified it to include JPGs.  Thank you!

                          • 10. Re: Place images to a specific spot in a template
                            Bestsides

                            Thank you , JJ Mack!!! I have wanted to do this same thing Sara describes - For me I wanted to quickly and easily create Folder Preview Image JPEGs using several images inside of the folder. I was able to easily make an action to resize the images and save them to a folder. But I never fully figured out how to get those images on to my various templates (8 images, 16 images, etc...) and clipped to the masks. Your scripts are magical to me! I am not someone who knows how to script but I knew enough to know this was the best way to achieve what I wanted. Your Tool Kit and postings had great instructions and videos and have made one of my Mac tasks SO simple and such a time saver. THANKS!!

                            • 11. Re: Place images to a specific spot in a template
                              schroef Level 1

                              c.pfaffenbichler Doesnt work on OSX, it returns

                               

                              'Null is not an Object'

                              • 12. Re: Place images to a specific spot in a template
                                c.pfaffenbichler Level 9

                                What does not work?

                                Please post the Script you use and a screenshot of Photoshop (including the pertinent Panels) at time of the error.

                                • 13. Re: Place images to a specific spot in a template
                                  schroef Level 1

                                  Re: Place images to a specific spot in a template

                                   

                                  This wont work, i dont get to pick a folder nor does go to a folder. Tried both methods. I keeps showing files only.

                                   

                                  But im not even sure this what i was looking for, it seems this script places links in open images according do a selected llist from file selection.    

                                  • 14. Re: Place images to a specific spot in a template
                                    c.pfaffenbichler Level 9

                                    Do you work on a Mac?

                                    And why did you append the issue to this thread?

                                    • 16. Re: Place images to a specific spot in a template
                                      c.pfaffenbichler Level 9

                                      Once again: Please post the Script you use.