Copy link to clipboard
Copied
How to resize an image layer to the same size as the width of the document respecting its aspect ratio.
...#target photoshop;
if(documents.length){
var doc = app.activeDocument;
var layer = doc.activeLayer;
var per = doc.width.value/(layer.bounds[2]-layer.bounds[0])*100;
layer.resize(per,per);
doc.selection.selectAll();
align('AdCH');
align('AdCV' );
doc.selection.deselect();
}
function align(method){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref
Copy link to clipboard
Copied
#target photoshop;
if(documents.length){
var doc = app.activeDocument;
var layer = doc.activeLayer;
var per = doc.width.value/(layer.bounds[2]-layer.bounds[0])*100;
layer.resize(per,per);
doc.selection.selectAll();
align('AdCH');
align('AdCV' );
doc.selection.deselect();
}
function align(method){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
};
Copy link to clipboard
Copied
Perfect, thanks ""! How nice that you came back SuperMerlin, I missed you friend ...