Copy link to clipboard
Copied
Hi all,
I've been racking my brains and the forums/Google et al for a day to try and find a working solution for my problem. I'm trying to have a script run through either a folder of psd files, or, a bunch of open psd files and quick export each of them to png. I'm part way there, I have a working script that successfully does them one at once;
var document = app.activeDocument;
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var saveIn = File("myLocalPathHere" + Name + ".png");
document.exportDocument(saveIn, ExportType.SAVEFORWEB);
Where myLocalPathHere is my actual physical path to the output folder.
If I open this script in Photoshop it will run fine on the currently displayed document but no more.
My skills are basic at best so I'm trying to find if someone's done this before and could point me in the right direction?
Thanks! D
I adapted the following scripts back in 2019 from another script, I'd probably do things differently now, but they should serve the intended purpose. Check the code you may wish to disable the sRGB conversion and or enable the flatten option.
Using Save:
#target photoshop
// Batch Save As sRGB PNG.jsx
displayDialogs = DialogModes.NO
// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx
if (BridgeTalk.appName == "photoshop")
...
Copy link to clipboard
Copied
I'll post code for this later when I have more time.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I adapted the following scripts back in 2019 from another script, I'd probably do things differently now, but they should serve the intended purpose. Check the code you may wish to disable the sRGB conversion and or enable the flatten option.
Using Save:
#target photoshop
// Batch Save As sRGB PNG.jsx
displayDialogs = DialogModes.NO
// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx
if (BridgeTalk.appName == "photoshop") {
app.bringToFront;
var inputFolder = Folder.selectDialog("Select the source folder that contains the files to save as PNG:");
if (inputFolder != null) {
// Add/remove file types as necessary
var fileList = inputFolder.getFiles(/\.(psd|psb|tif?f|jpe?g|png)$/i);
var outputFolder = inputFolder;
for (var i = 0; i < fileList.length; i++) {
if (fileList[i] instanceof File) {
var document = open(fileList[i]);
var documentName = fileList[i].name.replace(/\.[^\.]+$/, ''); // Regex remove filename extension
while (app.documents.length) {
var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".png");
// document.flatten (); // Disable flatten image step
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ConvertTosRGBProfile() {
app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var pngOptions = new PNGSaveOptions();
pngOptions.compression = 0
pngOptions.interlaced = false;
app.activeDocument.saveAs(newFile, pngOptions, true, Extension.LOWERCASE);
app.activeDocument.close();
}
}
if (i == fileList.length - 1) {
alert("The files have been saved as PNG files!");
}
}
}
}
Using Export/Save for Web:
#target photoshop
// Batch Export SfW sRGB PNG.jsx
displayDialogs = DialogModes.NO
// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx
if (BridgeTalk.appName == "photoshop") {
app.bringToFront;
var inputFolder = Folder.selectDialog("Select the source folder that contains the files to export as PNG:");
if (inputFolder != null) {
// Add/remove file types as necessary
var fileList = inputFolder.getFiles(/\.(psd|psb|tif?f|jpe?g|png)$/i);
var outputFolder = inputFolder ;
for (var i = 0; i < fileList.length; i++) {
if (fileList[i] instanceof File) {
var document = open (fileList [i]);
var documentName = fileList [i].name.replace(/\.[^\.]+$/, ''); // Regex remove filename extension
while (app.documents.length) {
var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".png");
// document.flatten (); // Disable flatten image step
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ConvertTosRGBProfile() {
app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // false = PNG-24
exportOptions.transparency = true; // true = transparent
exportOptions.interlaced = false; // true = interlacing on
exportOptions.includeProfile = true; // false = don't embedd ICC profile
document.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);
document.close(SaveOptions.DONOTSAVECHANGES);
}
}
if (i == fileList.length - 1) {
alert("The files have been saved as PNG files!");
}
}
}
}
Copy link to clipboard
Copied
Amazing! Worked first time exactly as I needed, thank you for saving me a headache today! Can I ask, are you finding the pngSaveOptions (for example) in a specific resource somewhere? All I could find was documentation from 2020 at best on the CEP Resources github https://github.com/Adobe-CEP/CEP-Resources/tree/master/Documentation/Product%20specific%20Documentat... - is this still valid and the go-to for the info I need do you know?
Thanks ever so much again, you've saved me so much time!
D
Copy link to clipboard
Copied
Yes, the PDF scripting guides are still valid and useful for ExtendScript/JavaScript programming (but not for UXP).
An online version:
Copy link to clipboard
Copied
Thanks! Much appreciated!
D
Copy link to clipboard
Copied
Some other options with a GUI that include PNG:
Image Processor Pro:
https://sourceforge.net/projects/ps-scripts/files/Image%20Processor%20Pro/v3_2%20betas/
Picture Processor:
https://github.com/Paul-Riggott/PS-Scripts/blob/master/Picture%20Processor.jsx
Raw Image Converter:
https://github.com/SetTrend/Raw-Image-Converter
Batch Multi Save:
https://www.marspremedia.com/software/photoshop/batch-multi-save
Batch Web Images:
https://www.marspremedia.com/software/photoshop/batch-web-images
Extended version of Image Processor by the late Mike Hale:
Copy link to clipboard
Copied
Thanks! I'll review these too! 🙂
Copy link to clipboard
Copied
Thank.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now