12 Replies Latest reply on Nov 7, 2012 4:22 PM by JJMack

    Resize all layers

    hazelsmrf Level 1

      I'm looking for a way to resize all the layers in my document to a specific size.  I'd like to resize every layer to be exactly 6 inches in height (while keeping proportions constrained).   I can manually transform every layer to do this but I haven't found a way to do this automatically to all layers,  is this possible?   I've tried to do it as an action but it's recording it as a percentage and not a fixed height,  so it doesn't work on the other layers that aren't the exact same size. 

        • 1. Re: Resize all layers
          PECourtejoie Adobe Community Professional

          Hello, did you try to record the change of units in the action?

          But I'm wondering if this is not rather a task for a script...

          • 2. Re: Resize all layers
            hazelsmrf Level 1

            I didn't,  I just input "6 inches" into the dialogue box (that was in %).   I'm not really sure how to get the action to "see" that change.   This may very well be something a script would need to do,  which would be beyond my abilities I think!   I was just hoping there was some Photoshop functionality that I was overlooking that would let me do this,  but if not then sizing every layer manually as I've been doing will continue to be part of my workflow.    Or I'll find a way to resize all of my groups in Illustrator before bringing them into Photoshop,  that may actually be a better solution.

            • 3. Re: Resize all layers
              arc fixer Level 3

              Hi.

               

              Something that may or may not be helpful. Resize your Ps canvas to H=6" before you paste in your Illy objects. Preexisting artwork in the Ps doc will be clipped, but it is still there at its original size. Paste your Illy objects into the Ps doc. They will resize as you want, H=6", aspect ratio retained, if H is equal to or greater than 6" in Illy before you paste. Easy enough to insure this. Then you can resize your canvas back to the original size revealing the preexisting Ps art and the imported Illy objects at the correct height.

               

              Whether this will work for you depends of course on the details of your workflow.

               

              Lee

              • 4. Re: Resize all layers
                Paul Riggott Level 6

                Here is a script that will resize SELECTED layers to 6" in height.

                 

                 

                #target photoshop
                function main(){
                if(!documents.length) return;
                var selectedLayers = getSelectedLayersIdx();
                for (var z in selectedLayers){
                selectLayerByIndex(Number(selectedLayers[z]));
                resizeLayer();
                    }
                }
                main();
                function resizeLayer(){
                var startRulerUnits = app.preferences.rulerUnits;
                app.preferences.rulerUnits = Units.PIXELS;
                var doc = activeDocument;
                var res= doc.resolution;
                var LB = activeDocument.activeLayer.bounds;
                var Height = LB[3].value - LB[1].value;
                var onePix = 100/Height;
                var newSize = onePix * (res * 6);
                doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER); 
                app.preferences.rulerUnits = startRulerUnits;
                }
                function selectLayerByIndex(index,add){ 
                 add = (add == undefined)  ? add = false : add;
                 var ref = new ActionReference();
                    ref.putIndex(charIDToTypeID("Lyr "), index);
                    var desc = new ActionDescriptor();
                    desc.putReference(charIDToTypeID("null"), ref );
                       if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
                      desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
                   try{
                    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
                }catch(e){}
                };
                function getSelectedLayersIdx(){ 
                      var selectedLayers = new Array; 
                      var ref = new ActionReference(); 
                      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                      var desc = executeActionGet(ref); 
                      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){ 
                         desc = desc.getList( stringIDToTypeID( 'targetLayers' )); 
                          var c = desc.count 
                          var selectedLayers = new Array(); 
                          for(var i=0;i<c;i++){ 
                            try{ 
                               activeDocument.backgroundLayer; 
                               selectedLayers.push(  desc.getReference( i ).getIndex() ); 
                            }catch(e){ 
                               selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); 
                            } 
                          } 
                       }else{ 
                         var ref = new ActionReference(); 
                         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); 
                         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                         try{ 
                            activeDocument.backgroundLayer; 
                            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); 
                         }catch(e){ 
                            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); 
                         } 
                      } 
                      return selectedLayers; 
                };
                
                
                 
                • 5. Re: Resize all layers
                  hazelsmrf Level 1

                  Paul,  thank you so much!  That script works perfectly.   A million thank yous!

                  • 6. Re: Resize all layers
                    rome1304

                    Hey Paul  great script I'm already making use of it  thanks! One question, Is there a way to make also fit 6" width I'm working on square documets with 7 layers each.  4 of them have to be sresized in width and 3 of them in height. Can this script be modified in some way?

                    • 7. Re: Resize all layers
                      Paul Riggott Level 6

                      This script might meet your needs better as you can select your layers/resize value and width/height also method.

                      http://www.scriptsrus.talktalk.net/ResizeLayers.htm

                      • 8. Re: Resize all layers
                        rome1304 Level 1

                        Hey Paul thanks for  your answer, however this is  more of a problem because I have to make the input manualy and one layer at a time. I'm looking  for something like a fit image to 6" but aplied to selected layer" I think I'm not explaining my goal I'm sending you a screenshot of the result of your great script so I can explain myself better. Screen Shot 2012-11-07 at 2.05.49 PM.png

                        Ypur script is working perfectly on layers 3, 5, 6 and 7

                         

                        Thanks again!

                        • 9. Re: Resize all layers
                          Paul Riggott Level 6

                          That script should work on selected layers, but if you want the same as the above script but resizing on width this should do that...

                           

                           

                          #target photoshop
                          function main(){
                          if(!documents.length) return;
                          var selectedLayers = getSelectedLayersIdx();
                          for (var z in selectedLayers){
                          selectLayerByIndex(Number(selectedLayers[z]));
                          resizeLayer();
                              }
                          }
                          main();
                          function resizeLayer(){
                          var startRulerUnits = app.preferences.rulerUnits;
                          app.preferences.rulerUnits = Units.PIXELS;
                          var doc = activeDocument;
                          var res= doc.resolution;
                          var LB = activeDocument.activeLayer.bounds;
                          var Width = LB[2].value - LB[0].value;
                          var onePix = 100/Width;
                          var newSize = onePix * (res * 6);
                          doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER); 
                          app.preferences.rulerUnits = startRulerUnits;
                          }
                          function selectLayerByIndex(index,add){ 
                           add = (add == undefined)  ? add = false : add;
                           var ref = new ActionReference();
                              ref.putIndex(charIDToTypeID("Lyr "), index);
                              var desc = new ActionDescriptor();
                              desc.putReference(charIDToTypeID("null"), ref );
                                 if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
                                desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
                             try{
                              executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
                          }catch(e){}
                          };
                          function getSelectedLayersIdx(){ 
                                var selectedLayers = new Array; 
                                var ref = new ActionReference(); 
                                ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                                var desc = executeActionGet(ref); 
                                if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){ 
                                   desc = desc.getList( stringIDToTypeID( 'targetLayers' )); 
                                    var c = desc.count 
                                    var selectedLayers = new Array(); 
                                    for(var i=0;i<c;i++){ 
                                      try{ 
                                         activeDocument.backgroundLayer; 
                                         selectedLayers.push(  desc.getReference( i ).getIndex() ); 
                                      }catch(e){ 
                                         selectedLayers.push(  desc.getReference( i ).getIndex()+1 ); 
                                      } 
                                    } 
                                 }else{ 
                                   var ref = new ActionReference(); 
                                   ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); 
                                   ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                                   try{ 
                                      activeDocument.backgroundLayer; 
                                      selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); 
                                   }catch(e){ 
                                      selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); 
                                   } 
                                } 
                                return selectedLayers; 
                          };
                          
                          
                          
                          • 10. Re: Resize all layers
                            JJMack Most Valuable Participant

                            Thanks Paul I always wanted to know how to process selected layers well.  

                             

                            The OP may want to catch the transform resizeLayer error that will happen if the background layer is selected. Put out a  message or just ignore the error.

                            function resizeLayer(){

                                      

                                     

                                      try{

                                                doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER);

                                                }

                                      catch(e){alert(doc.activeLayer + " Layer not resized ");}

                                      app.preferences.rulerUnits = startRulerUnits;

                            }

                            • 11. Re: Resize all layers
                              rome1304 Level 1

                              Great! thanks! not exactly as I thought, but in the end I did an action with your height script, select layers, your widh script and then save. Thanks a lot!

                              • 12. Re: Resize all layers
                                JJMack Most Valuable Participant

                                rome1304 wrote:

                                 

                                Hey Paul thanks for  your answer, however this is  more of a problem because I have to make the input manualy and one layer at a time. I'm looking  for something like a fit image to 6" but aplied to selected layer"

                                Fit Image is a plug-in script thate resizes documents. You may be able to modify the fit image script and replace the resizeimage with a process like Paul provided here for selected layers. The Fit Image dialog has both width and height fields and support actions. So you can record the use of your plug-in script in an action which will record the width and height into the action step and the plug-in will bypass displaying its dialog when the action is played. Remember Layers can be larger then and smaller then canvas size as well as canvas size.  So the layer transform may be up or down in size.  You will need to use layer bounds not document width and height like Fit image does for its calculations.  If you make the script a plug-in get a new uuid for it. You may also may want to have an option like fit image not to scale up if a layer fits as is.