can't make my JS script to work in Photoshop
Hello everyone.
I'm trying to make a PS script that would merge one by one all the PNG files from a directory with a background image, and save it in another folder.
I came up with that script :
// Background image directory and name
var backgroundDir = new Folder("bg_image");
var backgroundFile = backgroundDir + "/background_image.jpg";
// Logos directory and files
var logoDir = new Folder("logo");
var logoFiles = logoDir.getFiles("*.png");
// logo loop
for (var i = 0; i < logoFiles.length; i++) {
// open background image and get current logo
var backgroundDoc = app.open(backgroundFile);
var logoFile = logoFiles[i];
// New Layer for logo and load it
var logoLayer = backgroundDoc.artLayers.add();
logoLayer.place(logoFile);
// Resize logo and Set logo height to 90% of background height
var logoHeight = backgroundDoc.height * 0.9;
logoLayer.resize(undefined,logoHeight);
// Center logo on the picture
logoLayer.translate(backgroundDoc.width/2 - logoLayer.bounds.width/2,backgroundDoc.height/2 - logoLayer.bounds.height/2);
// final save
var finalDir = new Folder("final");
if(!finalDir.exists) {
finalDir.create();
}
var finalFile = new File(finalDir + "/" + logoFile.name.replace(/\.[^\.]+$/, '') + "_final.jpg");
backgroundDoc.saveAs(finalFile, new JPEGSaveOptions(), true);
// close background image
backgroundDoc.close(SaveOptions.DONOTSAVECHANGES);
}
But it doesn't seem to work and i can't see where is my mistake.
I dont have any error message, but nothing happens.
What i do is just launching PS2023, then go to file/scripts/browse and load my JS. But nothing happens like no script was charged 😞
Any help would be appreciated 🙂
