How to resize an image layer to the same size as the width of the document respecting its aspect ratio.
How to resize an image layer to the same size as the width of the document respecting its aspect ratio.

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 );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
};
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.