@Jamie Squared
Here is a batch version:
/*
Batch All Layer Comps x3 Sizes to JPEG.jsx
v1.1, 15th May 2024 - Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-both-export-and-resize-layer-comps/td-p/14614232
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/droplets-and-export-layer-comps-to-files/td-p/14585398
https://community.adobe.com/t5/photoshop-ecosystem-discussions/a-script-that-would-pack-layercomps-into-rgba-channels-and-saving-in-chosen-file-format/m-p/13906491
*/
#target photoshop
(function () {
var inputFolder = Folder.selectDialog("Please select the input folder:");
// Test if Cancel button returns null, then do nothing
if (inputFolder === null) {
app.beep();
return;
}
var outputFolder = Folder.selectDialog("Please select the output folder:");
// Test if Cancel button returns null, then do nothing
if (outputFolder === null) {
app.beep();
return;
}
var fileList = inputFolder.getFiles(/\.(psd|psb|tif|tiff)$/i);
//alert(fileList.length + " files will be processed...");
var theConfirmation = (confirm(fileList.length + " source files will be processed. Continue?", false));
// Test if the No button returns false, then do nothing
if (theConfirmation === false) {
app.beep();
return;
}
app.togglePalettes();
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
var fileCounter = 0;
for (var l = 0; l < fileList.length; l++) {
open(fileList[l]);
if (app.activeDocument.layerComps.length) {
try {
//var theSavePath = Folder.selectDialog("Select the output folder:");
var theSavePath = Folder('~/Desktop/JPEG_Comps');
if (!theSavePath.exists) {
theSavePath.create();
}
} catch (e) {
var theSavePath = Folder('~/Desktop/');
}
deleteDocumentAncestorsMetadata();
removeCRSmeta();
removeXMP();
// 300 ppi
app.activeDocument.resizeImage(app.activeDocument.width.value, app.activeDocument.height.value, 300, null);
for (i = 0; i < app.activeDocument.layerComps.length; i++) {
app.activeDocument.layerComps[i].apply();
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var compName = app.activeDocument.layerComps[i].name.replace(/\.[^\.]+$/, '');
var filePath = new File(theSavePath + "/" + docName + "_300ppi_" + compName + ".jpg");
saveCompToJPG();
}
// 144 ppi
app.activeDocument.duplicate(docName, false);
app.activeDocument.resizeImage(null, null, 144, ResampleMethod.BICUBIC);
for (i = 0; i < app.activeDocument.layerComps.length; i++) {
app.activeDocument.layerComps[i].apply();
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var compName = app.activeDocument.layerComps[i].name.replace(/\.[^\.]+$/, '');
var filePath = new File(theSavePath + "/" + docName + "_144ppi_" + compName + ".jpg");
saveCompToJPG();
}
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
// 72 ppi
app.activeDocument.resizeImage(null, null, 72, ResampleMethod.BICUBIC);
for (i = 0; i < app.activeDocument.layerComps.length; i++) {
app.activeDocument.layerComps[i].apply();
var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var compName = app.activeDocument.layerComps[i].name.replace(/\.[^\.]+$/, '');
var filePath = new File(theSavePath + "/" + docName + "_72ppi_" + compName + ".jpg");
saveCompToJPG();
}
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
} else {
//alert("The document must contain layer comps!");
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
///// Functions /////
function saveCompToJPG() {
try {
var jpgOptns = new JPEGSaveOptions();
jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
jpgOptns.embedColorProfile = true;
jpgOptns.matte = MatteType.NONE;
jpgOptns.quality = 10;
app.activeDocument.saveAs(filePath, jpgOptns, true, Extension.LOWERCASE);
fileCounter++;
} catch (e) {
alert("Error!" + "\r" + e + ', Line: ' + e.line);
}
}
function removeXMP() {
//https://community.adobe.com/t5/photoshop/script-to-remove-all-meta-data-from-the-photo/td-p/10400906
if (!documents.length) return;
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
XMPUtils.removeProperties(xmp, "", "", XMPConst.REMOVE_ALL_PROPERTIES);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
function removeCRSmeta() {
//community.adobe.com/t5/photoshop/remove-crs-metadata/td-p/10306935
if (!documents.length) return;
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
XMPUtils.removeProperties(xmp, XMPConst.NS_CAMERA_RAW, "", XMPConst.REMOVE_ALL_PROPERTIES);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
function deleteDocumentAncestorsMetadata() {
whatApp = String(app.name); //String version of the app name
if (whatApp.search("Photoshop") > 0) { //Check for photoshop specifically, or this will cause errors
if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(app.activeDocument.xmpMetadata.rawData);
// Begone foul Document Ancestors!
xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "DocumentAncestors");
app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}
}
}
app.togglePalettes();
app.displayDialogs = restoreDialogMode;
alert('Script completed!' + '\n' + fileList.length + ' source files have created ' + fileCounter + ' layer comps, saved to:' + '\r\r' + outputFolder.fsName);
})();