main();
function main(){
if(!documents.length) return;
if (activeDocument.activeLayer.kind != LayerKind.SMARTOBJECT) return;
/////////////////////////////// Amend to suit /////////////////////////////////
var Percent = 25; /* Resize logo to percentage of smallest side of doc */
var OffsetX = 0; /* Move logo pixels to the right - left */
var OffsetY = 20; /* Move logo pixels up - down. */
var Opacity = 100; /* Opacity of logo */
/////////////////////////////////////////////////////////////////////////////////////////////
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDoc = activeDocument;
rasterLayer();
var LB = myDoc.activeLayer.bounds;
var docHeight = myDoc.height;
var docWidth = myDoc.width;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);
var percentageHeight = ((docHeight/LWidth)*Percent);
var percentageWidth = ((docWidth/LWidth)*Percent);
if(docWidth < docHeight){
myDoc.activeLayer.resize(percentageWidth,percentageWidth,AnchorPosition.MIDDLECENTER);
}else{
myDoc.activeLayer.resize(percentageHeight,percentageHeight,AnchorPosition.MIDDLECENTER);
}
activeDocument.selection.selectAll();
// align methods
// 'AdCH' - center horizontal
// 'AdCV' - center vertical
// 'AdLf' - left
// 'AdRg' - Right
// 'AdBt' - bottom
// 'AdTp' - Top
align('AdCH');
align('AdTp');
activeDocument.selection.deselect();
activeDocument.activeLayer.translate(OffsetX,OffsetY);
activeDocument.activeLayer.opacity=Opacity;
app.preferences.rulerUnits = startRulerUnits;
}
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 );
};
function rasterLayer() {
var desc9 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc9.putReference( charIDToTypeID('null'), ref4 );
executeAction( stringIDToTypeID('rasterizeLayer'), desc9, DialogModes.NO );
};