29 Replies Latest reply on Aug 24, 2017 1:30 AM by natrev

    Duplicate and fit

    geppettol66959005 Level 3

      I have this need

       

      I would duplicate the document in use

       

      Resize to 1920px

       

      Return the document to the original

      And adapt it to the original document size

       

      Without having too much loss of quality.

        • 1. Re: Duplicate and fit
          c.pfaffenbichler Level 9

          Could you please illustrate with screenshots?

          To me it seems you want to resize an image and then resize it to the original size again – what good would that be?

          • 2. Re: Duplicate and fit
            geppettol66959005 Level 3

            I hope you understand

             

            Duplicate image

            Schermata 2017-08-22 alle 11.20.04.png

             

            After duplicate image

            Resize to 1024px

             

            Schermata 2017-08-22 alle 11.21.10.png

             

            Once resized to bring on original

             

            Schermata 2017-08-22 alle 11.21.46.png

             

            Fit to image without losing too much quality

            • 3. Re: Duplicate and fit
              c.pfaffenbichler Level 9

              What do you mean by

              Fit to image without losing too much quality

              ?

              Do you want to upscale the downsampled copy?

              • 4. Re: Duplicate and fit
                geppettol66959005 Level 3

                I would like to adapt it this way

                 

                Sorry if I do not speak English well and my tongue

                1111.png

                • 5. Re: Duplicate and fit
                  natrev Level 3

                  Hi

                   

                  Try this code...

                   

                  var strtRulerUnits = app.preferences.rulerUnits;
                  var strtTypeUnits = app.preferences.typeUnits;
                  app.preferences.rulerUnits = Units.PIXELS;
                  app.preferences.typeUnits = TypeUnits.PIXELS
                  
                  
                  cTID = function(s) {return app.charIDToTypeID(s);};
                  sTID = function(s) {return app.stringIDToTypeID(s);};
                  if(documents.length>0) main();
                  function  main(){
                      var docRef = app.activeDocument;   
                      var docname=activeDocument.name;
                      var theCopy = docRef.duplicate("Dup",true);
                      app.activeDocument=theCopy;
                      c_Res=theCopy.resolution;
                      if(theCopy.height.value>theCopy.width.value){ theCopy.resizeImage(undefined,new UnitValue(1024,'Px'),c_Res, ResampleMethod.AUTOMATIC);}
                      else{theCopy.resizeImage(new UnitValue(1024,'Px'), undefined, c_Res, ResampleMethod.AUTOMATIC);}     
                      var theLayer=theCopy.backgroundLayer.duplicate();  
                      theLayer.duplicate (docRef, ElementPlacement.PLACEATBEGINNING);
                      theCopy.close(SaveOptions.DONOTSAVECHANGES);
                      app.activeDocument=docRef;
                      docRef.selection.selectAll();
                      align('AdCV');
                      align('AdCH');
                      docRef.selection.deselect();
                  }
                  
                  
                  // Align Layer
                  function align(method) {  
                    var desc = new ActionDescriptor();  
                    var ref = new ActionReference();  
                    ref.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) );  
                    desc.putReference( cTID( "null" ), ref );  
                    desc.putEnumerated( cTID( "Usng" ), cTID( "ADSt" ), cTID( method ) );  
                    try{  
                    executeAction( cTID( "Algn" ), desc, DialogModes.NO );  
                    }catch(e){}  
                  }  
                  
                  
                  

                   

                  - yajiv

                  1 person found this helpful
                  • 6. Re: Duplicate and fit
                    c.pfaffenbichler Level 9

                    You mean align to the center?

                    if so why duplicate the image and resize instead of just the Layer?

                    • 7. Re: Duplicate and fit
                      geppettol66959005 Level 3

                      Natrev is on the right track

                       

                      Now I want to fit the original picture

                      • 8. Re: Duplicate and fit
                        c.pfaffenbichler Level 9

                        Now I want to fit the original picture

                        Again: What do you mean?

                        If you posted meaningful screenshots you could save some typing …

                         

                        The task (or what you have revealed of it so far) seems close to nonsensical to me – what is the purpose of the operation?

                        • 9. Re: Duplicate and fit
                          natrev Level 3

                          Hi

                           

                          Now, Try this code..

                           

                          var strtRulerUnits = app.preferences.rulerUnits;
                          var strtTypeUnits = app.preferences.typeUnits;
                          app.preferences.rulerUnits = Units.PIXELS;
                          app.preferences.typeUnits = TypeUnits.PIXELS
                          cTID = function(s) {return app.charIDToTypeID(s);};
                          sTID = function(s) {return app.stringIDToTypeID(s);};
                          if(documents.length>0) main();
                          function  main(){
                              var docRef = app.activeDocument;   
                              var docname=activeDocument.name;
                              var ImgW=docRef.width.value
                              var ImgH=docRef.height.value   
                              var theCopy = docRef.duplicate("Dup",true);
                              app.activeDocument=theCopy;
                              c_Res=theCopy.resolution;   
                              if(theCopy.height.value>theCopy.width.value){ theCopy.resizeImage(undefined,new UnitValue(1024,'Px'),c_Res, ResampleMethod.AUTOMATIC);}
                              else{theCopy.resizeImage(new UnitValue(1024,'Px'), undefined, c_Res, ResampleMethod.AUTOMATIC);}     
                              var theLayer=theCopy.backgroundLayer.duplicate();  
                              theLayer.duplicate (docRef, ElementPlacement.PLACEATBEGINNING);
                              theCopy.close(SaveOptions.DONOTSAVECHANGES);
                              app.activeDocument=docRef;
                              docRef.selection.selectAll();
                              align('AdCV');
                              align('AdCH');
                              docRef.selection.deselect();
                              var theLayer=docRef.activeLayer;    
                              var LB = theLayer.bounds;
                              var lWidth = LB[2].value - LB[0].value;
                              var lHeight = LB[3].value - LB[1].value;  
                              if(lWidth>lHeight){
                                  x=(ImgW/lWidth)*100; 
                                  theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);
                              }  
                              else{
                                  var x=(ImgH/lHeight)*100;
                                  theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);
                              }    
                          }
                          // Align Layer
                          function align(method) {  
                            var desc = new ActionDescriptor();  
                            var ref = new ActionReference();  
                            ref.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) );  
                            desc.putReference( cTID( "null" ), ref );  
                            desc.putEnumerated( cTID( "Usng" ), cTID( "ADSt" ), cTID( method ) );  
                            try{  
                            executeAction( cTID( "Algn" ), desc, DialogModes.NO );  
                            }catch(e){}  
                          }  
                          
                          
                          

                           

                          -yajiv

                          1 person found this helpful
                          • 10. Re: Duplicate and fit
                            natrev Level 3

                            Hi

                             

                            Try this code also..

                             

                            var strtRulerUnits = app.preferences.rulerUnits;  
                            var strtTypeUnits = app.preferences.typeUnits;  
                            app.preferences.rulerUnits = Units.PIXELS;  
                            app.preferences.typeUnits = TypeUnits.PIXELS  
                              
                            if(documents.length>0) main();  
                            function  main(){  
                                var docRef = app.activeDocument;     
                                var ImgW=docRef.width.value
                                var ImgH=docRef.height.value  
                                var docname=activeDocument.name;  
                                docRef.flatten();
                                c_Res=docRef.resolution;  
                                var theLayer=docRef.backgroundLayer.duplicate(); 
                                var LB = theLayer.bounds;
                                var lWidth = LB[2].value - LB[0].value;
                                var lHeight = LB[3].value - LB[1].value;  
                            
                            
                                if(lWidth>lHeight){
                                    x=(1024/lWidth)*100; 
                                    theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);
                                }  
                                else{
                                    var x=(1024/lHeight)*100;
                                    theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);
                                }    
                            
                            
                                var theLayer=docRef.layers[0];    
                                docRef.activeLayer=theLayer;
                                if(lWidth>lHeight){        
                                    x=(ImgW/1024)*100; 
                                    theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);
                                }  
                                else{
                                    var x=(ImgH/1024)*100;
                                    theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);
                                }    
                            }  
                            

                             

                            -yajiv

                            • 11. Re: Duplicate and fit
                              c.pfaffenbichler Level 9

                              It’s nice of you to write the code but what do you think the use/benefit/aim of the procedure is?

                              • 12. Re: Duplicate and fit
                                natrev Level 3

                                Hi Chris,

                                 

                                I understood what is your saying. However what I understood, the Image size going to be reduced with same pixel dimension. That's the reason I written code.

                                 

                                -yajiv

                                • 13. Re: Duplicate and fit
                                  c.pfaffenbichler Level 9

                                  But would certain Filters not achieve a very similar result (with regard to damage and savings)?

                                  • 14. Re: Duplicate and fit
                                    JJMack Most Valuable Participant

                                    geppettol66959005  wrote

                                     

                                    I have this need

                                     

                                    I would duplicate the document in use

                                     

                                    Resize to 1920px

                                    Because you wrote 1920 it leads me to believes you want to display the resized image on a  1920x1080 display.  If an  image does not have a 16:9 aspect ratio and you resize it to fit within 1920x1080 pixels there will be borders.   Photoshop has a Plug-in named Fit Image that you can record in an action and batch to resize image to fit within 1920x1080 pixels.  Menu File >Automate>Fit Image record 1920width 1080 height.  Or you can use menu Scripts>Image Processor and fill in its dialog and have it resize images to fit within 1920x1080.  I will use Fit Image to do the resize.

                                     

                                    If you do not  want boarders on images that do not have a 16:9 aspect Ratio you could try using Photoshop Content Aware Resize.   The will be distortion. Photoshop will try to preserve object it recognizes perspective,  However you should not expect square  and portrait aspect ration image to resize well into a wide 16:9 landscape Aspect ratio image.  Cropping to 16:9 also will not  work well with square and portrait images to much image content will be cropped off the resulting composition will not be acceptable.

                                    • 15. Re: Duplicate and fit
                                      Davide_Barranca Level 1

                                      Hi,

                                      can you provide a bit of background on the rationale behind your request, please?

                                      Basically, you're downsampling an image ("Fit to Image" to a smaller size), and then upsampling it ("Fit to Image" back to the original size). Which, inherently, is going to cause a loss of quality – how much, it depends on the original image's size.

                                       

                                      In other words, what you're asking for is a "quality loss machine", but at the same time "Without having too much loss of quality" – that's the puzzling part.

                                       

                                      Davide

                                      • 16. Re: Duplicate and fit
                                        geppettol66959005 Level 3

                                        You are right in asking why this is my request

                                         

                                        I need to duplicate the document and resize it

                                        To perform operations on level masks

                                        Which then bring it on the original document and fit it into the image

                                         

                                        I think in this passage I do not have much loss of quality.

                                         

                                        Thanks for your help

                                        • 17. Re: Duplicate and fit
                                          c.pfaffenbichler Level 9

                                          To perform operations on level masks

                                          Why would those not work on the fullers image?

                                          • 18. Re: Duplicate and fit
                                            geppettol66959005 Level 3

                                            I tried to do it on the original image

                                            But you lose too much time

                                             

                                            Then I tried it with resized image and much faster

                                             

                                            So the work I have in mind and this

                                             

                                            Duplicate in a new document

                                             

                                            reduce

                                             

                                            To do the work on the masks

                                             

                                            Bring the document to the original

                                             

                                            Fit resized photos to the original.

                                            • 19. Re: Duplicate and fit
                                              c.pfaffenbichler Level 9

                                              From a quality point of view what you are proposing to do seems like a bad idea.

                                               

                                              What exactly do you mean by »perform operations on level masks«?

                                              Why does it take so long, what are the original fullres images’ usual pixel dimensions and bit depths?

                                              • 20. Re: Duplicate and fit
                                                geppettol66959005 Level 3

                                                The dimensions in px 7360 × 4912 and even bigger bit16

                                                 

                                                What exactly do you mean by "performing layer masks"?

                                                 

                                                I mean blur on masks in various rays.

                                                • 21. Re: Duplicate and fit
                                                  c.pfaffenbichler Level 9

                                                  Then why do you not transfer and upsample the Layer Masks instead of degrading the composite image content?

                                                  • 22. Re: Duplicate and fit
                                                    JJMack Most Valuable Participant

                                                    Yes it seems what they need to do is scale the layer mask they developed up in size to fit the original image. The results should be good for they seem to want to create a blurred mask in the first place. An Upsize mask should not hurt the masking quality too much. Going from 1k back to 8K is a big change in the number of pixels like 8x

                                                    • 23. Re: Duplicate and fit
                                                      geppettol66959005 Level 3

                                                      natrev

                                                      Your scripts are fine

                                                      But there is a misunderstanding

                                                      It should not duplicate the image

                                                      But must duplicate the document

                                                      • 24. Re: Duplicate and fit
                                                        JJMack Most Valuable Participant

                                                        Have no Idea of what you would the want to mask in duplicated document resized 1920

                                                        #target photoshop;  
                                                        app.bringToFront();  
                                                        if (documents.length)  app.activeDocument.suspendHistory('ResizDupe1920','main()');
                                                        ///////////////////////////////////////////////////////////////////////////////
                                                        //                            main function                                  //
                                                        ///////////////////////////////////////////////////////////////////////////////
                                                        function main() {
                                                           var strtRulerUnits = app.preferences.rulerUnits; // Save Users ruler units 
                                                           app.preferences.rulerUnits = Units.PIXELS;       // work with pixels 
                                                           activeDocument.duplicate();                      // Duplicate Document
                                                           activeDocument.resizeImage(1920, null, null, ResampleMethod.BICUBICSMOOTHER); 
                                                           app.preferences.rulerUnits = strtRulerUnits;     // Restore user ruler units  
                                                        }
                                                        
                                                        1 person found this helpful
                                                        • 25. Re: Duplicate and fit
                                                          geppettol66959005 Level 3

                                                          JJMack

                                                          Thank you

                                                          The first step has been made

                                                           

                                                          Now it would serve another small code it should

                                                          Bring the processed document to the source document to fit it

                                                          All original image

                                                          • 26. Re: Duplicate and fit
                                                            JJMack Most Valuable Participant

                                                            Why what would that do for you.  You wrote about masking the 1920 document for faster performance for Photoshop is dealing with 1/8 the number of pixels the original  document has.  That you want to create a blurred mask using various blur tools.  I think you need to create that mask in the second 1920 document. Then once created you need copy that mask into the original document. Then Scale the copied mask  for the original document size.

                                                            • 27. Re: Duplicate and fit
                                                              natrev Level 3

                                                              Hi

                                                               

                                                              Do you check my code? ( 9th reply of this thread )

                                                              I have posted two code one for Duplicate the image and another one for duplicate the layer.

                                                               

                                                              -yajiv

                                                              • 28. Re: Duplicate and fit
                                                                geppettol66959005 Level 3

                                                                natrev

                                                                 

                                                                Now I've seen it

                                                                Thanks to everyone for help

                                                                • 29. Re: Duplicate and fit
                                                                  natrev Level 3

                                                                  Hi geppettol66959005,

                                                                   

                                                                  Please mark as correct answer if the answer is fulfil your requirement.

                                                                   

                                                                  -yajiv