Skip to content

Instantly share code, notes, and snippets.

@Ending2015a
Created January 21, 2024 09:29
Show Gist options
  • Save Ending2015a/cde33e8a0b36818baec352fecb124dbf to your computer and use it in GitHub Desktop.
Save Ending2015a/cde33e8a0b36818baec352fecb124dbf to your computer and use it in GitHub Desktop.
Photopea export all group layers (folders) into separated PNG files.
function GetDocName(){
var split = app.activeDocument.name.split('.');
split.pop();
var docName = split.join(".");
return docName;
}
function SavePNG(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = false;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
function ExportLayers(){
var layers = app.activeDocument.layers;
var docName = GetDocName();
var numLayers = layers.length;
var excludeLast = true;
if(excludeLast) numLayers--;
for (var i=0;i<numLayers; i++){
for (var j=0;j<layers.length; j++){
layers[j].visible = false;
}
layers[i].visible = true;
SavePNG(docName + '-' + layers[i].name + '.png');
}
}
ExportLayers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment