Photoshop CS6上的JavaScript错误(随机图像创建者)



我当前正在使用此脚本,但Photoshop CS6在运行时显示此错误错误图像示例

这个脚本需要进行哪些编辑才能在Photoshop CS6上运行?此外,我需要更改什么才能将图像保存为JPEGS而不是PNGS

谢谢

function Visible() {
var Grps = app.activeDocument.layerSets; // loops through all groups
for(var i = 0; i < Grps.length; i++){
var tmp = app.activeDocument.layerSets[i].layers.length;
app.activeDocument.layerSets[i].visible=true;
var groupChildArr = app.activeDocument.layerSets[i].layers;
var randLays = Math.floor(Math.random() * tmp);
groupChildArr[randLays].visible = true;
Save();
}
Revert();
}
function Save() {
var outFolder = app.activeDocument; // psd name
var outPath = outFolder.path;
var fName = "PNG";   // define folder name
var f = new Folder(outPath + "/" + fName);
if ( ! f.exists ) {
f.create()
}
var saveFile = new File(outPath + "/" + fName +"/" + "Pattern_" +  num + ".png");
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function Revert(){
var idslct = charIDToTypeID( "slct" );
var desc300 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref163 = new ActionReference();
var idSnpS = charIDToTypeID( "SnpS" );
ref163.putName( idSnpS, "test.psd" );
desc300.putReference( idnull, ref163 );
executeAction( idslct, desc300, DialogModes.NO );
}
var count = prompt("How many patterns you want","");
for (var x=0 ; x<count;x++){
var num = x+1;
Visible();
}

PNG没有与JPEG相同的选项,因此复制和替换对您没有帮助。

// png file options
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
// jpg file options
var jpgFile = new File(saveFile);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = 12; // or whatever jpeg quality you want. 12 is max
app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);

revert函数导致了您的错误。更改为:

function Revert()
{
var idRvrt = charIDToTypeID( "Rvrt" );
executeAction( idRvrt, undefined, DialogModes.NO );
}

最新更新