Copy link to clipboard
Copied
Hi everyone!
I have a frame mockup design in .psd. I want to batch create mockups in the form of .jpegs for all images from a folder (thousands of files). I am trying to get a script to work but continually get errors. I am saving the script as .jsx.
The process should go as follows:
1. My images are located in the folder Images in New folder on my desktop. The mockups should go to folder Images mockup in the New folder on my desktop. I have a mockup design called 0001 mockup glavna slika.psd
2. The images should be placed inside the YOUR DESIGN smart object layer, on top of the white background.
3. The images are saved as .psd or .jpg in the Images mockup folder
I tried to write a script but it isn't working.
#target photoshop
var sourceFolder = new Folder("C:/Users/poste/Desktop/New folder/Images");
var outputFolder = new Folder("C:/Users/poste/Desktop/New folder/Images mockup");
var templatePath = new File("C:/Users/poste/Desktop/New folder/0001 mockup glavna slika.psd");
if (!sourceFolder.exists || !templatePath.exists || !outputFolder.exists) {
alert("One of the folders or the template file does not exist. Please check the paths.");
exit();
}
var files = sourceFolder.getFiles(function(file) {
return (file instanceof File && file.name.match(/\.(jpg|jpeg|png|tif|tiff|psd)$/i));
});
for (var i = 0; i < files.length; i++) {
var currentFile = files[i];
placeOnTopInTemplate(currentFile, templatePath);
}
function placeOnTopInTemplate(imageFile, template) {
var doc = app.open(template);
var smartObjectLayer = findLayerByName(doc, "YOUR DESIGN");
if (!smartObjectLayer) {
alert("Could not find the layer named 'YOUR DESIGN'.");
doc.close(SaveOptions.DONOTSAVECHANGES);
return;
}
var tempPSB = new File(Folder.temp + '/temp.psb');
smartObjectLayer.smartObject.exportContents(tempPSB);
var tempDoc = app.open(tempPSB);
var imageDoc = app.open(imageFile);
imageDoc.activeLayer.copy();
imageDoc.close(SaveOptions.DONOTSAVECHANGES);
tempDoc.paste();
tempDoc.save();
tempDoc.close(SaveOptions.SAVECHANGES);
smartObjectLayer.smartObject.replaceContents(tempPSB);
tempPSB.remove();
var saveName = outputFolder + "/mockup_" + imageFile.name;
var saveFile = new File(saveName);
var saveOptions = new PhotoshopSaveOptions();
doc.saveAs(saveFile, saveOptions, true);
doc.close(SaveOptions.DONOTSAVECHANGES);
}
function findLayerByName(doc, name) {
for (var i = 0; i < doc.layers.length; i++) {
var layer = doc.layers[i];
if (layer.name === name) {
return layer;
}
if (layer.typename === "LayerSet") {
var foundLayer = findLayerByName(layer, name); // Recursive search in groups
if (foundLayer) return foundLayer;
}
}
return null;
}
I would be really grateful for help. Thank you so much.
Copy link to clipboard
Copied
@Mislav28755659f88e – You don't even need to use smart object replacements:
https://github.com/MarshySwamp/JJMack-Archive
This archive contains scripts for collages or smart object replacement mockups, you don't need to write any code, you just need to ensure that your files are setup according to the "simple rules" that the script requires.