36 Replies Latest reply on Aug 24, 2018 8:36 AM by bobsaidwzob

    How to fit image in particular frame?

    claudiop42841845 Level 1

      Hi all, me again with a new trouble.

       

      I'm trying to insert a photo inside a file, so I can standardize the rest of my collection.

       

      I tested all the scripts I found and tips on FIT IMAGE TO FRAME but no success.

       

      Where am I going wrong?

       

      Below is the image I want and where I need to put it

       

      ATIMES.jpg

      DS COVER.png

       

       

      My goal

       

      ATIMES FULL.jpg

      How to make this?? I have 320 images to make this, any Actions tip?

       

      Thanks in advance.

       

       

      Claudio

        • 1. Re: How to fit image in particular frame?
          c.pfaffenbichler Level 9

          As perspectival foreshortening seems to be involved I would recommend creating a master file with a transformed Smart Object and switch in the images in turn.

          There have een several threads on the Photoshop Scripting Forum on automating such processes.

           

          But if the images do not all have the same relative dimensions you should set up a rule: clip or add white/black/… space?

          2 people found this helpful
          • 2. Re: How to fit image in particular frame?
            claudiop42841845 Level 1

            Thanks c.pfaffenbichler .

             

            All imagers are same resolution and extension.

             

            I need transformation Ds model in Smart Object, correct? After this, how to insert a image?

             

             

             

            Claudio

            • 3. Re: How to fit image in particular frame?
              c.pfaffenbichler Level 9
              I need transformation Ds model in Smart Object, correct?

              The translation may be off, but the transformation should be applied to the Smart Object in the containing document.

              Then replacing the Smart Object’s content with the other images would apply the same transformation to those.

               

              Check out these threads for example:

              Batch replace smart objects in mockup file

              Batch replace smart objects

              1 person found this helpful
              • 4. Re: How to fit image in particular frame?
                claudiop42841845 Level 1

                Hi c.pfaffenbichler,

                 

                I tried to use your script and that's just it.

                 

                Where am I going wrong? Images have the same resolution.

                 

                SNAG-0959.jpg

                SNAG-0960.jpg

                SNAG-0961.jpg

                 

                 

                Claudio

                • 5. Re: How to fit image in particular frame?
                  c.pfaffenbichler Level 9

                  If I understand your layout correctly you need at least two Layers:

                  • the frame

                  • the cover (as a transformed SO)

                  Screen Shot 2018-07-11 at 14.44.23.png

                  • 6. Re: How to fit image in particular frame?
                    claudiop42841845 Level 1

                    Hummm, Yes iThis is what I need.

                     

                    How to? Using the script ?

                    • 7. Re: How to fit image in particular frame?
                      c.pfaffenbichler Level 9

                      Sorry, there seems to be a misunderstanding.

                      First you need to set up the dummy file like this and then you can use a Script to automate switching in different content for the SO.

                      • 8. Re: How to fit image in particular frame?
                        claudiop42841845 Level 1

                        Make this.

                        SNAG-0962.jpg

                        But when use the script, give me the "Command SET is no avaliable"

                         

                        Used this script:

                        SNAG-0963.jpg

                         

                        Claudio

                        • 10. Re: How to fit image in particular frame?
                          claudiop42841845 Level 1

                          This:

                           

                          // 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], theLayer);

                                              var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];

                          //Raise color picker for Back cover;

                          try {

                          app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

                          // =======================================================

                          var idsetd = charIDToTypeID( "setd" );

                          var desc7 = new ActionDescriptor();

                          var idnull = charIDToTypeID( "null" );

                          var ref2 = new ActionReference();

                          var idcontentLayer = stringIDToTypeID( "contentLayer" );

                          var idOrdn = charIDToTypeID( "Ordn" );

                          var idTrgt = charIDToTypeID( "Trgt" );

                          ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

                          desc7.putReference( idnull, ref2 );

                          var idT = charIDToTypeID( "T   " );

                          var desc8 = new ActionDescriptor();

                          var idClr = charIDToTypeID( "Clr " );

                          var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

                          desc7.putObject( idT, idsolidColorLayer, desc8 );

                          executeAction( idsetd, desc7, DialogModes.ALL );

                          } catch (e) {};

                          //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) != null || theFile.constructor.name == "Folder") {

                                    return true

                                    };

                               };

                          ////// replace contents //////

                          function replaceContents (newFile, theSO) {

                          app.activeDocument.activeLayer = theSO;

                          // =======================================================

                          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

                          };

                          • 11. Re: How to fit image in particular frame?
                            Bojan Živković Adobe Community Professional

                            Can you please explain your goal further. You want to automate the process of replacing image on single Smart Object layer and then to save in some format like JPEG. As already mentioned you will need layer with the frame and Smart Object layer with image to replace. From what I see above you want to replace image on Smart Object layer which is below the frame and you have and Background layer at the bottom.

                            Action can be recorded for that purpose. There are several options in my head. Simples action will be to use Replace Contents command which will open dialog to select image for replacement but in that case you must manually select each and every of 320 images for replacement.

                            If I know exactly your end goal and steps perhaps there is more automated solution.

                            • 12. Re: How to fit image in particular frame?
                              claudiop42841845 Level 1

                              Thank you for help Bojan Živković.

                               

                              My first goal is to fit any image 1 to frame. fill the transparent inner space. That would do me good.

                               

                              Image 1

                              Image 1.jpg

                               

                              Frame

                              Frame.jpg

                               

                              Final Image Result

                              Final Result Image.jpg

                               

                              My second goal is to replace the 1 image with other images and save via PNG / JPG automatized.

                               

                               

                              Claudio

                              • 13. Re: How to fit image in particular frame?
                                Bojan Živković Adobe Community Professional

                                I found some quick solution which seems to work. Requirement for action to work is template which must have image to be replaced as it is as starting point. The next step is to convert image to Smart Object layer and to transform it. If you do not understand then solution can be to upload frame and one of the images somewhere so I can access them to try things on my own and test process.

                                • 14. Re: How to fit image in particular frame?
                                  claudiop42841845 Level 1

                                  Hi Bojan, I make it but some step is missing on my mind.

                                   

                                  Here: 3DS.zip - Google Drive

                                   

                                  Its contain 2 files.

                                   

                                  Thanks,

                                   

                                  Claudio

                                  • 15. Re: How to fit image in particular frame?
                                    Bojan Živković Adobe Community Professional

                                    I have created template and recorded action. Download it from here Claudio files.zip - Google Drive  You will need Image Processor Pro installed ps-scripts - Browse /Image Processor Pro at SourceForge.net . I am running 2.3.0 version while testing. Note: I will assume that all your images which you want to use for replacement are 940x842px with single layer present.

                                     

                                    • Open PSD template which I have prepared in Photoshop.
                                    • Load action Batch replace SO content (it is included with template)
                                    • With template with frame claudio.psd open in Photoshop (I am repeating just to ensure) evoke Image Processor Pro from File > Automate.
                                    • Choose folder with images at the top (section 1)
                                    • Choose where to save images (section 2)
                                    • In section 3 (File types) you should have 2 tabs: one to save JPEG and another to save PNG files. That's what I have understood, you want JPEG and PNG files saved. Important thing is to check Run Action. From the first drop down list choose Batch replace SO content and from the second choose: Replace SO content. That is action set name and action name which I sent you. Check Run Action on both tabs to run action for both: JPEG and PNG files.

                                    claudio setup.jpg

                                    Test with a couple of images like 5 or 6 to see if everything works as you expect.

                                    Ensure that you have the second (latest version downloaded). In the first version, I forgot to merge layers in edited SO layer what will create a huge file when batch processing lots of images.

                                    2 people found this helpful
                                    • 16. Re: How to fit image in particular frame?
                                      claudiop42841845 Level 1

                                      Sir Bojan Živković  you are my hero.

                                       

                                      Thank you very much for your help. English is not my native language, so I suffer from a few sentences.

                                       

                                      Thanks for the patience with me.

                                       

                                      I will now finalize my project and I will try to read and learn more about Photoshop.

                                       

                                      You have won a fan.

                                       

                                      Covers.jpg

                                       

                                       

                                      Claudio

                                      • 17. Re: How to fit image in particular frame?
                                        bobsaidwzob Level 1

                                        I found this article very helpful and I am trying to do the same thing with a playstation 2 template. I followed these instruction and the automation seems to work other than the fact that the image does not get resized to fit the template. Some of it gets cut off and does not get skewed and it would if I did it manually. I followed these instructions and cannot figure out where I am going wrong. And is there a way to not have a white background show up? Thanks.

                                         

                                        Backyard Football '10_1.jpg

                                        • 18. Re: How to fit image in particular frame?
                                          Bojan Živković Adobe Community Professional

                                          Are you using the same template? It won't work. The action is created to work with some dependencies specific to Claudio's files.

                                          You can upload frame and image somewhere so I can create a template for you.

                                           

                                          Note: for action above to work, your images (not frame) must have exact same dimensions (width and height).

                                          • 19. Re: How to fit image in particular frame?
                                            bobsaidwzob Level 1

                                            Gotcha. I was not using the same file but followed the same steps. I did't realize the template was had specific dependencies. I just assumed that it would work. All of the images will be the same dimensions so that won't be an issue.  I have a few other templates I plan to work on after the playstation 2 one. Is it difficult to create a template for these? Just asking for future reference.

                                             

                                            I really appreciate your help.

                                            Angry Birds - Star Wars.png

                                             

                                            Nintendo 3DS 3D Box Template.png

                                             

                                            101 In 1 Party Megamix.png

                                            Nintendo Wii 3D Box Template.png

                                             

                                            2010 FIFA World Cup - South Africa.png

                                             

                                            Sony PSP 3D Box Template.png

                                             

                                            007 - Agent Under Fire.png

                                            Sony Playstation 2 3D Box Template.png

                                            • 20. Re: How to fit image in particular frame?
                                              c.pfaffenbichler Level 9

                                              That Script had an additional step t set a color for the back-cover, below is an amended version.

                                              The gif shows running the Script on an image with a transformed Smart Object selected and selecting three mock-up covers and then the resulting images.

                                              smartObjectGameCoverSm.gif

                                               

                                              // replace smart object’s content and save psd;

                                              // 2018, use it at your own risk;

                                              #target "photoshop-120.032"

                                              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], theLayer);

                                              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|png)$/i) != null || theFile.constructor.name == "Folder") {

                                                        return true

                                                        };

                                                   };

                                              ////// replace contents //////

                                              function replaceContents (newFile, theSO) {

                                              app.activeDocument.activeLayer = theSO;

                                              // =======================================================

                                              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

                                              };

                                              2 people found this helpful
                                              • 21. Re: How to fit image in particular frame?
                                                Bojan Živković Adobe Community Professional

                                                Here are some guidelines on how to create template to use with action provided above

                                                 

                                                Just to mention that you have step: Trim at the bottom of the action which is turned off from playing. You can turn it on in case that you want to trim transparent areas. Just above step Trim you will see step: Reveal all which is also excluded from playing. Those steps are recorded initially just in case... Whole action is recorded to serve with modified template like added layer for clipping mask below replace Smart Object layer.

                                                • 22. Re: How to fit image in particular frame?
                                                  bobsaidwzob Level 1

                                                  Thank you very much for that video. It worked like a charm. Is there any way to have the script not automatically create a white background? I want it to be transparent. Since my wii covers are white, they blend in with the white background and there's no way for me remove the background with removing parts of the template. Thanks.

                                                  • 23. Re: How to fit image in particular frame?
                                                    claudiop42841845 Level 1

                                                    Another great help for thread!!

                                                     

                                                    Thanks again Sir Bojan Živković.

                                                     

                                                    Im shared with my friends. subscribe YT too!!

                                                     

                                                    Claudio

                                                    • 24. Re: How to fit image in particular frame?
                                                      Bojan Živković Adobe Community Professional

                                                      Hi, bobsaidwzob , are you referring to script postet by c.pfaffenbichler  or to my action?

                                                      Action is not creating any background. Action is expecting single layer in replacement image files.

                                                      • 25. Re: How to fit image in particular frame?
                                                        bobsaidwzob Level 1

                                                        I'm referring to this file. "Batch replace SO content.atn". It was included in the google drive attachments at the beginning of the thread. So if it doesn't create a background it there a way to have a transparent background instead of white? By default a new image has a white background so I'm guessing that's where it occurs. I can choose a transparent background manually but I'm not sure how to do that via this script.

                                                         

                                                        Here is an example of the white background from the automation process. Screen Shot 2018-07-12 at 4.56.05 PM.png

                                                        Screen Shot 2018-07-12 at 4.57.48 PM.png

                                                        • 26. Re: How to fit image in particular frame?
                                                          bobsaidwzob Level 1

                                                          The issue is the jpg format. The White background doesn't show up if I choose psd as the file format. Not sure if it's the replace file causing that or what but I guess I'll just be using the psd format from now on. If there is a fix for the jpg format that would be better but psd will do for now.

                                                          • 27. Re: How to fit image in particular frame?
                                                            Bojan Živković Adobe Community Professional

                                                            The second image should be a template which is open before evoking Image Processor Pro and batch process, right? Remove white background on the layer with the frame. You can use any selection technique that you know. Just mask white background or delete it.

                                                             

                                                            I just saw your explanation about JPEG file. You can save as PNG to keep transparent areas. Above lines are still valid, template must have transparent areas, not white background if you want transparency in saved PNG, PSD files.

                                                            • 28. Re: How to fit image in particular frame?
                                                              bobsaidwzob Level 1

                                                              I've been using this method for almost anything i can think of. I have run into an issue where I'm a little stumped on how to fix. Every image goes perfectly into place but there is a space in the middle where I would like to keep white. Instead, you see the previous images  from this batch. Is there a way to not show the previous images in the middle? I've attached an example so you can better see what I'm talking about. I've using the batch script you provided. If there is a way to adjust that script let me know.

                                                               

                                                              In the picture you can see the blue and yellow which I do not wan there. I have a bunch of images where the middle portion does not line up everytime but If there was a way to remove the previous image before the top layer pastes, that would probably solve my issue.

                                                               

                                                              Thanks.

                                                               

                                                              Air Ranger - Rescue Helicopter.png

                                                              • 29. Re: How to fit image in particular frame?
                                                                Bojan Živković Adobe Community Professional

                                                                I've been using this method for almost anything i can think of.

                                                                Can you give us more details about method? Which particular method?

                                                                • 30. Re: How to fit image in particular frame?
                                                                  bobsaidwzob Level 1

                                                                  I've attached a video showing what i'm doing. It's basically the same script you provided up abode in this thread.

                                                                   

                                                                  Untitled - YouTube

                                                                  • 31. Re: How to fit image in particular frame?
                                                                    Bojan Živković Adobe Community Professional

                                                                    From the first look at your video, it seems to me that problem is layer to which is clipped SO layer and bottom layer with cast shadow because they both have content which is showing in the final exported image.

                                                                    When you clip something to layer below it will replace pixels but you will have problem when you have no content (transparency) on layer which is clipped to layer below. In that case pixels on layer to which is clipped another layer will show up (white on your final image).

                                                                     

                                                                    Do you need clipping mask and why?

                                                                     

                                                                    Another problem is bottom most layer which is easier to solve, remove content (white ellipse) and leave only cast shadow. If you are using that layer to add white border around then you must have another approach and to look for a different solution.

                                                                     

                                                                    Here is quick solution which comes to my mind for clipping mask: do not clip SO layer but instead use ellipse to which is clipped to create selection for layer mask applied to SO layer then delete ellipse to which is clipped SO layer.

                                                                     

                                                                    Update: it seems that I have missed the point and what you really want. How many layers do you have in images which you are batch processing?

                                                                    • 32. Re: How to fit image in particular frame?
                                                                      bobsaidwzob Level 1

                                                                      Thank you for your help. To answer your update question, I want one layer, which it does create. I am using a tipping mask because it is easier for me to hide all the imperfections along the edges of that layer. I know there are other ways  around that but this was the easiest for me to do. In the end, I want one layer where the middle portions do not overlap.

                                                                       

                                                                      If removing the clipping mask will fix that then I will try that. If not, then I have to go through each file individually and remove that section.

                                                                      • 33. Re: How to fit image in particular frame?
                                                                        Bojan Živković Adobe Community Professional

                                                                        Your output images have desired image and one more image below from what I see on your video. Please correct me if that's not true.

                                                                         

                                                                        Action expects only one layer in images which you are batch processing and that layer will be deleted using one of the action step. If you have multiple layers in source images (images to batch process or folder with images in section 1 in Image Processor dialog) then you need another approach and additional steps in action to merge layers to a single layer).

                                                                         

                                                                        If you can not figure out what to do then please upload or deliver to me files: template and few images for batch process with detailed description what you want as output image: do you want transparent areas in the middle or you are ok with white in the middle circle?

                                                                        • 34. Re: How to fit image in particular frame?
                                                                          bobsaidwzob Level 1

                                                                          I still cannot figure it out. Ideally, I would like to have the middle portion transparent. I had a white middle because that was the only way I could figure out how to do a clipping mask.

                                                                           

                                                                          Template

                                                                          PS2 3D Disc Template.png

                                                                           

                                                                          Some files for batch

                                                                           

                                                                          10 Pin - Champions Alley.png24 - The Game.png25 To Life.png50 Cent - Bulletproof.png

                                                                           

                                                                          Is there a way to have the middle of each disc be placed in the exact same spot? Some middle portions are not in the same spot as the other discs and that might solve my issue if i could stretch out the other portions of the image and not keep the middle intact.

                                                                          • 35. Re: How to fit image in particular frame?
                                                                            Bojan Živković Adobe Community Professional

                                                                            My action provided above is not recorded for this type of problems. Action is suitable in case that you have images/designs which go inside of disc as a separate files. Images should not be distorted, that should be done after converting image to Smart Object layer in the file which will be used as template. Another component is frame or disc which should be above.

                                                                             

                                                                            Do you have images or designs which are inside disc as a separate files? That will work to use my action which you are trying to use.

                                                                            • 36. Re: How to fit image in particular frame?
                                                                              bobsaidwzob Level 1

                                                                              Unfortunately I don't have them in separate files. I found the images online and save them on my computer. I make the images the same size with a transparent background but that's all I can really do in order to automate what I'm trying to do. If I have to manually remove the middle portion then I will. I was hoping there might be an easier way. Thanks for your help!