Here the code to size the logo to the document width or height for best results. You can customize the size via the var LogoSize default is 100%
/* ==========================================================
// 2019 John J. McAssey (JJMack)
// ======================================================= */
// This script is supplied as is. It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
/*
<javascriptresource>
<about>$$$/JavaScripts/PlaceVectorLogo/About=JJMack's PlaceVectorLogo ^r^rCopyright 2019 Mouseprints.net^r^rPhotoshop Script^rCustomize var LogoSize</about>
<category>JJMack's Script</category>
</javascriptresource>
*/
#target photoshop;
app.bringToFront();
var logoFile = File.openDialog("Select Vector Logo" , "Select:*.svg;*.ai");
if (logoFile != undefined ) {
var LogoSize = 100; // Canvas Fill Percenttage
//placeLogo(logoFile, LogoSize); // Place Logo onto the document
app.activeDocument.suspendHistory('placeLogo','placeLogo(logoFile,LogoSize)' );
}
else alert('no Vector Logo file selected');
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function placeLogo(Image,Size){
if(!documents.length) return; // if no document return
var fileObj = new File(Image); // the passed file
if(!fileObj.exists){ // If file does not exits tell user
alert(fileObj.name + " does not exist!"); // Alert user
return; // return
}
try{
var doc = app.activeDocument; // set Doc object to active document
app.displayDialogs = DialogModes.NO; // Dialog off
var strtRulerUnits = app.preferences.rulerUnits; // Save Users ruler units
var strtTypeUnits = app.preferences.typeUnits; // Save Users Type units
app.preferences.rulerUnits = Units.PIXELS; // work with pixels
app.preferences.typeUnits = TypeUnits.PIXELS; // work with pixels
var layers = app.activeDocument.layers; // get layers
app.activeDocument.activeLayer = layers[0]; // Target Top Layer
placeFile(fileObj); // Place in file the Logo Vector file
activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER); // Insure Place did not scale layer
var docWidth = app.activeDocument.width.value; // get Canvas width
var docHeight = app.activeDocument.height.value; // get canvas Hieght
var docAspectRatio = docWidth/docHeight; // Canvas Aspect Ratio
var LB = app.activeDocument.activeLayer.bounds; // Get Active layers bounds
var LWidth = (LB[2].value) - (LB[0].value); // Area width
var LHeight = (LB[3].value) - (LB[1].value); // Area height
var sobjAspectRatio = LWidth/LHeight // Logo Aspect Ratio
if (sobjAspectRatio<docAspectRatio) { // layer's Aspect Ratio less the Canvas area Aspect Ratio
var percentageChange=((docHeight/LHeight)*Size);// resize to canvas area height
app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
}
else {
var percentageChange = ((docWidth/LWidth)*Size);// Resize to canvas area width
app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);
}
app.activeDocument.selection.selectAll(); // select all
align('AdCH'); // align to horizontal centers
align('AdCV'); // align to vertical centers
app.activeDocument.selection.deselect();
}
catch(e) { alert(e + ': on line ' + e.line); } // inform user of error
finally{
app.preferences.rulerUnits = strtRulerUnits; // Restore user ruler units
app.preferences.typeUnits = strtTypeUnits; // Restore user type units
};
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function placeFile(placeFile) {
var desc21 = new ActionDescriptor();
desc21.putPath( charIDToTypeID('null'), new File(placeFile) );
desc21.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') );
var desc22 = new ActionDescriptor();
desc22.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 );
desc22.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 );
desc21.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc22 );
executeAction( charIDToTypeID('Plc '), desc21, DialogModes.NO );
};
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 ) );
try{executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );}
catch(e){}
}