@PixelTonic
You can try the following script:
/*
All top level layers exported to PNG x2 Size.jsx
Stephen Marsh, 12th May 2023 - v1.1
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-layers-to-files-at-200-and-maintain-canvas-size/td-p/13787373
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-do-i-export-layers-as-png-without-loosing-the-size-and-placement-of-the-particular-layer/m-p/12734226
Note:
* Save before running the script if desired, as the doc will be closed without saving!
*/
#target photoshop
(function () {
if (app.documents.length > 0) {
imageSize(200, 200, 0);
try {
var outputPath = app.activeDocument.path.fsName;
} catch (e) {
var outputPath = Folder.selectDialog("Unsaved base file, select the output folder:");
}
var counter = 0;
for (var i = 0; i < app.activeDocument.layers.length; i++) {
for (var j = 0; j < app.activeDocument.layers.length; j++) {
app.activeDocument.layers[j].visible = false;
}
var layerIndex = i;
app.activeDocument.layers[layerIndex].visible = true;
var layerName = app.activeDocument.layers[layerIndex].name.replace(/[^a-z0-9 _-]/gi, '').replace(/ +|-+|_+$/g, '');
var filename = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var theFile = new File(outputPath + "/" + layerName + ".png");
// Prompt to overwrite existing file
if (theFile.exists) {
// true = 'No' as default active button
if (!confirm("File exists, overwrite: Yes or No?", true))
throw null;
//throw alert("Script cancelled!");
}
var pngOptions = new ExportOptionsSaveForWeb();
pngOptions.PNG8 = false;
pngOptions.transparency = true;
pngOptions.interlaced = false;
pngOptions.quality = 100;
pngOptions.includeProfile = true;
pngOptions.format = SaveDocumentType.PNG;
app.activeDocument.exportDocument(File(outputPath + "/" + layerName + ".png"), ExportType.SAVEFORWEB, pngOptions);
counter++;
}
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
alert(counter + " PNG files exported to:" + "\r" + outputPath);
} else {
alert("You must have a document open!");
}
})();
function imageSize(width, height, noise) {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
descriptor.putUnitDouble(s2t("width"), s2t("percentUnit"), width);
descriptor.putUnitDouble(s2t("height"), s2t("percentUnit"), height);
descriptor.putEnumerated(s2t("interfaceIconFrameDimmed"), s2t("interpolationType"), s2t("deepUpscale"));
descriptor.putInteger(s2t("noise"), noise);
executeAction(s2t("imageSize"), descriptor, DialogModes.NO);
}
NOTE: Save before running the script if desired, as the doc will be closed without saving!