Photoshop: Is there a way resize layers individually to same size and align them?

  • 2
  • Question
  • Updated 11 months ago
  • (Edited)
Is there a way to resize all the different layers I have (in one project) to be the same exact size other than manually dragging the handles? Ideally, also, they could be aligned next to each other in a grid as well, but maybe that is too much to ask. I need them to stay in different layers as well also.
I have photoshop cs4 and a mac.
Photo of ChristieT

ChristieT

  • 3 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 2
Photo of Jeffrey Tranberry

Jeffrey Tranberry, Sr. Product Manager, Digital Imaging

  • 14147 Posts
  • 1765 Reply Likes
There are a number of ways this could be achieved depending on the nature of the layers that need to be resized.

If all the layers are the same size, you could simply select all the layers and do a transform.

If they are all different sizes, you create a script to do this. ( check at PS-scripts.com as someone may already have a script to do this)

Another, brute force way would be to File>Scripts>Export Layers as Files... then do a batch or Image Processor on the images and then use File>Script>Load Files into Stack... to bring the resized files into Photoshop as layers.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
This should do it for selected layers...

 

#target photoshop
function main(){
if(!documents.length) return;
var win = new Window( 'dialog', 'RL' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.orientation='stack';
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Resize Selected Layers');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "row";
win.g5.alignment='center';
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Resize to...');
win.g5.et1 = win.g5.add('edittext');
win.g5.et1.preferredSize=[60,20];
resizeUnits = ["pixels", "inches","cm", "mm"];
win.g5.dd1 = win.g5.add('dropdownlist',undefined,resizeUnits);
win.g5.dd1.selection=0;
win.g5.et1.onChanging = function() {
if (this.text.match(/[^\-
#target photoshop
function main(){
if(!documents.length) return;
var win = new Window( 'dialog', 'RL' );
g = win.graphics;
var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);
g.backgroundColor = myBrush;
win.orientation='stack';
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.g1 = win.p1.add('group');
win.g1.orientation = "row";
win.title = win.g1.add('statictext',undefined,'Resize Selected Layers');
win.title.alignment="fill";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);
win.g5 =win.p1.add('group');
win.g5.orientation = "row";
win.g5.alignment='center';
win.g5.spacing=10;
win.g5.st1 = win.g5.add('statictext',undefined,'Resize to...');
win.g5.et1 = win.g5.add('edittext');
win.g5.et1.preferredSize=[60,20];
resizeUnits = ["pixels", "inches","cm", "mm"];
win.g5.dd1 = win.g5.add('dropdownlist',undefined,resizeUnits);
win.g5.dd1.selection=0;
win.g5.et1.onChanging = function() {
if (this.text.match(/[^\-\.\d]/)) {
this.text = this.text.replace(/[^\-\.\d]/g, '');
}
};
win.g10 =win.p1.add('group');
win.g10.orientation = "row";
win.g10.alignment='fill';
win.g10.spacing=10;
win.g10.bu1 = win.g10.add('button',undefined,'Process');
win.g10.bu1.preferredSize=[150,25];
win.g10.bu2 = win.g10.add('button',undefined,'Cancel');
win.g10.bu2.preferredSize=[150,25];
win.g10.bu1.onClick=function(){
if(win.g5.et1.text == ''){
alert("You have not entered a required size!");
return;
}
win.close(0);
Res = activeDocument.resolution;
Pixel = Number(win.g5.et1.text);
CM = Res/2.54;
MM = Res/25.4;
switch(win.g5.dd1.selection.index){
case 0 : break;
case 1 : Pixel = Pixel * Res; break;
case 2 : Pixel = Pixel * CM; break;
case 3 : Pixel = Pixel * MM; break;
default : break;
}
var selectedLayers = getSelectedLayersIdx();
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
for (var z in selectedLayers){
selectLayerByIndex(Number(selectedLayers[z]));
resizeLayer(Pixel);
}
app.preferences.rulerUnits = startRulerUnits;
}
win.center();
win.show();
}
main();

function resizeLayer(Pixel){
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 * Pixel;
doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER);
}
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
Photo of ChristieT

ChristieT

  • 3 Posts
  • 0 Reply Likes
Thank you for both responses. I think the first one should work for sure in at least one of those ways.
The second response looks fabulous, but it is totally over my head- I am not sure what to do with it. I hope that was a cut and paste thing and you didn't have to type the whole thing, but either way thank you very much!!!! They are so appreciated!!!!!
The people at "JustAnswer" couldn't give me ANY answer after 48 hours and just gave up and refunded my money-
You both rock!!
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
Copy and paste the code into ExtendScript Toolkit.
This utility can be found:-
PC: C:\Program Files\Adobe\Adobe Utilities
PC 64 bit C:\Program Files (x86)\Adobe\Adobe Utilities - CS5
MAC: /Applications/Utilities/Adobe Utilities

Save the script to the following folder:-
PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts

MAC: /Applications/Adobe Photoshop CS#/Presets/Scripts

N.B. if your are using Vista or Windows 7 you will need to save the script elsewhere and then copy it to the relevant folder, this is due to permissions.

If Photoshop was open close and restart it so that it can pick up the new script.

To assign an action and function key, start recording a new action, assign the function key you require, then from the action palette fly-out menu select "Insert Menu Item" now File - Scripts and select your new script. Stop the recording.

Now every time you press the function key it will run the script.

To use select the layers you want to resize and run the script.
Hope this helps.
Photo of ChristieT

ChristieT

  • 3 Posts
  • 0 Reply Likes
Thank you ! I love learning new things!!!! ;-)
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
This script might be of use to align selected layers...
http://www.scriptsrus.talktalk.net/Sp...
Photo of Eduart Milushi

Eduart Milushi

  • 2 Posts
  • 0 Reply Likes
404 Error
Photo of Jeffrey Tranberry

Jeffrey Tranberry, Sr. Product Manager, Digital Imaging

  • 14147 Posts
  • 1765 Reply Likes
Cool stuff Paul. Thanks.
Photo of Eduart Milushi

Eduart Milushi

  • 2 Posts
  • 0 Reply Likes
Doest it works on CS6?
Photo of Dmitry Konash

Dmitry Konash

  • 1 Post
  • 0 Reply Likes
There are in code some syntax errors