Skip to main content
mauricior6328708
Inspiring
November 12, 2016
Answered

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

  • November 12, 2016
  • 1 reply
  • 1359 views

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

This topic has been closed for replies.
Correct answer SuperMerlin

#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 );

};

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
November 12, 2016

#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 );

};

mauricior6328708
Inspiring
November 12, 2016

Perfect, thanks ""! How nice that you came back SuperMerlin, I missed you friend ...