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!");
}
}
}
}