Skip navigation
Currently Being Moderated

Resize all layers

Mar 22, 2012 7:41 AM

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. 

 
Replies
  • PECourtejoie
    4,228 posts
    Jan 11, 2006
    Currently Being Moderated
    Mar 22, 2012 7:45 AM   in reply to hazelsmrf

    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...

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2012 11:05 AM   in reply to hazelsmrf

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2012 12:21 PM   in reply to hazelsmrf

    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; 
    };
    
    
     
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2012 12:27 PM   in reply to Paul Riggott

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2012 12:46 PM   in reply to rome1304

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2012 1:12 PM   in reply to Paul Riggott

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2012 1:24 PM   in reply to rome1304

    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; 
    };
    
    
    
     
    |
    Mark as:
  • JJMack
    2,393 posts
    Jan 9, 2006
    Currently Being Moderated
    Nov 7, 2012 4:41 PM   in reply to Paul Riggott

    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;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 7, 2012 5:03 PM   in reply to Paul Riggott

    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!

     
    |
    Mark as:
  • JJMack
    2,393 posts
    Jan 9, 2006
    Currently Being Moderated
    Nov 7, 2012 5:22 PM   in reply to rome1304

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points