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 ); };
More discussions in Photoshop Scripting
adobe
Comments
Post a Comment