Advertisement
joonaspaakko

Photoshop - Resize Each Layer script

Jun 27th, 2013
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     - Photoshop script ( cs3+ )
  4.     - Put in {photoshop_root}/presets/scripts/Resize Each Layer.jsx
  5.     - Run from: File > Scripts > Resize Each Layer
  6.     - ..or save the file where ever you want and run from there with: File > Scripts > Browse...
  7.  
  8.     EVERY LAYER is resized when you run the script.
  9.  
  10. */
  11.  
  12. /*
  13.  
  14.     <javascriptresource>
  15.     <name>$$$/JavaScripts/resizeeachlayer/Menu=Resize Each Layer</name>
  16.     <category>Resizing</category>
  17.     <enableinfo>true</enableinfo>
  18.     <eventid>64feff0a-8271-436f-8c59-d2105497d903</eventid>
  19.     </javascriptresource>
  20.  
  21. */
  22.  
  23. try {
  24.  
  25.         // Currently active document.
  26.         var doc = app.activeDocument;
  27.  
  28.     // All layers
  29.     var layers = doc.artLayers;
  30.    
  31.     // Run dialog...
  32.     var size = dialog();
  33.  
  34.     // Loop through every layer...
  35.     for( var i = 0 ; i < doc.artLayers.length; i++ ){
  36.  
  37.         var activeLayer = doc.artLayers.getByName( doc.artLayers[ i ].name  );
  38.  
  39.         // Save original ruler units
  40.         var orUnits = app.preferences.rulerUnits;
  41.  
  42.         // Change rulerunits to percent
  43.         app.preferences.rulerUnits = Units.PERCENT;
  44.        
  45.         // RESSIIIIIIIZE
  46.         activeLayer.resize( size, size, AnchorPosition.MIDDLECENTER );
  47.  
  48.         // Roll back to original ruler units
  49.         app.preferences.rulerUnits = orUnits;
  50.    
  51.     }
  52.  
  53.  
  54. } // try end
  55.  
  56. catch( e ) {
  57.     // remove comments below to see error for debugging
  58.     // alert( e );
  59. }
  60.  
  61.  
  62. function dialog() {
  63.  
  64.     // Dialog box...
  65.     var myWindow = new Window ("dialog", "Resize Each Layer");
  66.  
  67.     // Keeps things inline
  68.     myWindow.orientation = "row";
  69.  
  70.     // Informational text
  71.     myWindow.add ("statictext", undefined, "New size ( percentage ):");
  72.  
  73.     // This is the box where the size is inserted
  74.     var myText = myWindow.add ("edittext", undefined, "");
  75.     myText.characters = 5;
  76.     myText.active = true;
  77.    
  78.     // Ok....
  79.     myWindow.add ("button", undefined, "OK");
  80.     if (myWindow.show () == 1) return myText.text;
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement