Za předpokladu, nejspodnější vrstva je Vrstva Pozadí, nahoře máme tři obrázky, které jsou barevné pozadí. Nad těmi je tvé umění.
to je právě případ určit, které vrstvy jsou které a první přechod je všechno PRYČ a pak NA na turnu.
var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var n = (numOfLayers - backgrounds.length)-1;
var backgrounds = ["Red", "Yellow", "Blue"];
// switch backgrounds OFF
for (var i = n; i < numOfLayers-1; i++)
{
srcDoc.layers[i].visible = false;
}
// switch them ON one at at time
for (var i = n; i < numOfLayers-1; i++)
{
srcDoc.layers[i].visible = true;
// save
var myFileName = "C:\\temp\\my_picture_" + i + ".jpg";
save_as_jpg(myFileName);
// Switch it off again
srcDoc.layers[i].visible = false;
}
function save_as_jpg(afilepath)
{
duplicate_it();
// Flatten the jpg
activeDocument.flatten();
// jpg file options
var jpgFile = new File(afilepath);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12;
activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
//close without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function duplicate_it()
{
// duplicate image into new document
var str = "temp";
var id428 = charIDToTypeID( "Dplc" );
var desc92 = new ActionDescriptor();
var id429 = charIDToTypeID( "null" );
var ref27 = new ActionReference();
var id430 = charIDToTypeID( "Dcmn" );
var id431 = charIDToTypeID( "Ordn" );
var id432 = charIDToTypeID( "Frst" );
ref27.putEnumerated( id430, id431, id432 );
desc92.putReference( id429, ref27 );
var id433 = charIDToTypeID( "Nm " );
desc92.putString( id433, str ); // name
executeAction( id428, desc92, DialogModes.NO );
}