Copy link to clipboard
Copied
Hi all,
I've tried to write a script to process 800 high resolution files that I have - I need to resize them to smaller dimensions, place another image on top of them and save with a new filename. With below script it fails with Error 4 on Line 2. Adobe Photoshop has full permission to folders on my device.
// Define the folder containing the files
var folderPath = "/Users/drcs/Desktop/Circuits/To print/Cropped_lowres/tracks/”;
// Define the path to the image to be placed on top
var overlayImagePath = "/Users/drcs/Desktop/Circuits/To print/Cropped_lowres/tracks/frame.png”;
// Open all files in the folder
var files = Folder(folderPath).getFiles(„*.png”); // Adjust the file extension if needed
// Open the overlay image
var overlayFile = new File(overlayImagePath);
var overlayDoc = app.open(overlayFile);
// Loop through each file
for (var i = 0; i < files.length; i++) {
var file = files[i];
// Open the file
var doc = app.open(file);
// Duplicate the overlay image
var overlayLayer = overlayDoc.artLayers[0];
overlayLayer.duplicate(doc, ElementPlacement.PLACEATBEGINNING);
// Close the overlay document without saving changes
overlayDoc.close(SaveOptions.DONOTSAVECHANGES);
// Resize the image
doc.resizeImage(2480, 3543);
// Save the modified image under a new filename
var fileName = file.name.slice(0, -4); // Remove the file extension (.png)
var newFileName = fileName + „_framed.png”; // Append "_resized" to the original filename
var newFile = new File(folderPath + newFileName); // Construct the new file path
doc.saveAs(newFile);
// Close the document
doc.close();
}
Any chance that you can help with this one guys?
Copy link to clipboard
Copied
var folderPath = "/Users/drcs/Desktop/Circuits/To print/Cropped_lowres/tracks/”;
Copy link to clipboard
Copied
wow, good eye, thank you!
Copy link to clipboard
Copied
Do not use complex editors to edit scripts. Use plain text without styles or special characters.By @r-bin
Common free or commercial plain text editors suitable for code editing and saving include –
Cross-platform: Atom, Sublime Text, MS Visual Studio Code + Adobe ExtendScript Debugger
Mac: Apple TextEdit (ensure that the Format menu is set to Plain Text mode, not Rich Text mode), BBEdit
Windows: MS Notepad, Adobe ExtendScript Toolkit (32-bit only), Notepad++
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html