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.
I didn't, I just input "6 inches" into the dialogue box (that was in %). I'm not really sure how to get the action to "see" that change. This may very well be something a script would need to do, which would be beyond my abilities I think! I was just hoping there was some Photoshop functionality that I was overlooking that would let me do this, but if not then sizing every layer manually as I've been doing will continue to be part of my workflow. Or I'll find a way to resize all of my groups in Illustrator before bringing them into Photoshop, that may actually be a better solution.
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
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;
};
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.
Ypur script is working perfectly on layers 3, 5, 6 and 7
Thanks again!
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;
};
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;
}
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.
North America
Europe, Middle East and Africa
Asia Pacific