Copy link to clipboard
Copied
Using Photoshop CS4 on a Mac with 10.6.8. I am working with a file that has several individual portraits as separate layers. All the portraits are approximately the same size, but I want to make them the exact same size (325 pixels by 325 pixels, not that it matters).
I tried highlighting several of the layers, then going to FILE > Scripts > "Make all selected layers the same size"
I have limited photoshop knowledge, and have never used a script before. I've tried closing and re-opening photoshop (my only technical knowledge: restart?!). I also tried googling the error, to no avail.
I have never used scripts...and have definitely never tried to change any scripts within Photoshop. Any specific ideas on how I can fix this would greatly be appreciated (and please remember that I'm still a beginner at this)
Thanks in advance!
You can download the full script from here..
Copy link to clipboard
Copied
I don't think that is a script that ships with Photoshop. Can you post the full script or a link to where you downloaded it from?
Copy link to clipboard
Copied
I am an IDIOT. Apparently my friend did try to put this in my computer to help me. He copied and pasted it from a suggestion he found on the internet:
[ code was mangled by the editor - removed by admin since it was incomplete and difficult to view. Try using the pre /pre HTML tags around it. ]
Copy link to clipboard
Copied
Thanks for your reply Michael!! I tried copying and pasting above...but it put in those column lines. Is that readable to you? Or is there a better way to paste it in?
Copy link to clipboard
Copied
One way to post code is to click on the 'Use advanced editor' link that is at the top left of the post window. That adds some new icons one of which is '>>' When you click on that you get a menu for inserting text. I use 'Syntax Highlighting->Plain'.
But from looking at what you posted before it was removed, I would say that the reason you are getting the error is the code is already scrambled. I would think that
#target photoshop
function main(){ if(!documents.length)
Should be the start of the script. But it is repeated later in the middle of an if statement. I think that 'double paste' in the code on your machine is the reason for your error.
Copy link to clipboard
Copied
#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
)); 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
Copy link to clipboard
Copied
You can download the full script from here..
Copy link to clipboard
Copied
Thank you Michael and Paul! Paul, I've downloaded your solution and it worked like a charm. THANK YOU!!