Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active February 7, 2025 12:19
Show Gist options
  • Save ZiTAL/b5538da08d8fefa095b9a7e78deb64b0 to your computer and use it in GitHub Desktop.
Save ZiTAL/b5538da08d8fefa095b9a7e78deb64b0 to your computer and use it in GitHub Desktop.
photoshop script: automatize add logo to images
displayDialogs = DialogModes.NO
var logoFile = File("C:/work/project/example/logo.png"); // Change to your logo path
var quality = 10
function processFolder(folder)
{
var files = folder.getFiles(); // Get all files and subfolders
for (var i = 0; i < files.length; i++)
{
var file = files[i];
if (file instanceof Folder) // If it's a folder, process it recursively
processFolder(file);
else if (file instanceof File && file.name.match(/_CIR\.psd$/i)) // Process only _CIR.psd files
processPSD(file);
}
}
function processPSD(psdFile)
{
var doc = app.open(psdFile); // Open PSD file
// Extract folder name and get numeric ID
var parentFolder = psdFile.parent.parent.name;
var folderID = parentFolder.match(/^\d+/); // Extract leading numbers
if (!folderID)
folderID = "Unknown"; // Default if no number found
else
folderID = folderID[0]; // Get the matched number
// Open and copy logo
var logo = app.open(logoFile);
logo.selection.selectAll();
logo.selection.copy();
logo.close();
var newLayer = doc.artLayers.add();
doc.paste(); // Paste logo
newLayer.name = "Logo";
// Move logo to the Top-Left corner
var xOffset = -newLayer.bounds[0].as("px"); // Shift logo to left
var yOffset = -newLayer.bounds[1].as("px"); // Shift logo to top
newLayer.translate(xOffset, yOffset);
// Save as a new PSD file
var newPsdFile = new File(psdFile.path + "/" + psdFile.name.replace(/\.psd$/, "_MOSCA.psd"));
var psdOptions = new PhotoshopSaveOptions();
doc.saveAs(newPsdFile, psdOptions, true, Extension.LOWERCASE);
// resize
doc.resizeImage(1500, 1500, null, ResampleMethod.BICUBIC);
// Export as JPG with folder ID
var jpgFile = new File(psdFile.path + "/../" + folderID + "_CIR_MOSCA.jpg");
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = quality; // Max quality
doc.saveAs(jpgFile, jpgOptions, true, Extension.LOWERCASE);
// Export as JPG to another folder
jpgFile = new File(psdFile.path + "/../../../MOSCA/" + folderID + "_CIR_MOSCA.jpg");
doc.saveAs(jpgFile, jpgOptions, true, Extension.LOWERCASE);
// Close PSD file
doc.close(SaveOptions.DONOTSAVECHANGES);
}
// Select the main folder
var mainFolder = Folder.selectDialog("Select Main Folder Containing _CIR.psd Files");
if (mainFolder)
processFolder(mainFolder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment