Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joonaspaakko/6053274 to your computer and use it in GitHub Desktop.
Save joonaspaakko/6053274 to your computer and use it in GitHub Desktop.
/*
This script resizes every layer within the active document.
How to use:
- Photoshop script ( cs3+ )
- Put in {photoshop_root}/presets/scripts/Resize Each Layer.jsx
- Run from: File > Scripts > Resize Each Layer
- ..or save the file where ever you want and run from there with: File > Scripts > Browse...
*/
/*
<javascriptresource>
<name>$$$/JavaScripts/resizeeachlayer/Menu=Resize Each Layer</name>
<category>Resizing</category>
<enableinfo>true</enableinfo>
<eventid>64feff0a-8271-436f-8c59-d2105497d903</eventid>
</javascriptresource>
*/
try {
// Currently active document.
var doc = app.activeDocument;
// All layers
var layers = doc.artLayers;
// Run dialog...
var size = dialog();
// Loop through every layer...
for( var i = 0 ; i < doc.artLayers.length; i++ ){
var activeLayer = doc.artLayers.getByName( doc.artLayers[ i ].name );
// Save original ruler units
var orUnits = app.preferences.rulerUnits;
// Change rulerunits to percent
app.preferences.rulerUnits = Units.PERCENT;
// RESSIIIIIIIZE
activeLayer.resize( size, size, AnchorPosition.MIDDLECENTER );
// Roll back to original ruler units
app.preferences.rulerUnits = orUnits;
}
} // try end
catch( e ) {
// remove comments below to see error for debugging
// alert( e );
}
function dialog() {
// Dialog box...
var myWindow = new Window ("dialog", "Resize Each Layer");
// Keeps things inline
myWindow.orientation = "row";
// Informational text
myWindow.add ("statictext", undefined, "New size ( percentage ):");
// This is the box where the size is inserted
var myText = myWindow.add ("edittext", undefined, "");
myText.characters = 5;
myText.active = true;
// Ok....
myWindow.add ("button", undefined, "OK");
if (myWindow.show () == 1) return myText.text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment