我有一个保存在某个位置的主文档。这份主文档有一个大 Sprite 。运行我的脚本时,会使用 Sprite 以各种模式创建多个新文档。我想将这些多个新文档另存为 PNG,而无需访问“另存为...”对话框并关闭它们。
// ==============================================================
// This code is run on the master document to get the Path.
// The saved directory location of the main master document.
Path = doc.path; // If the document is new there is no doc.path. Error is shown.
// ==============================================================
// ==============================================================
// This code is run at the end of the multiple new documents that's created.
// Save the file.
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Suffix = "";
var saveFile = File(Path + "/" + Name + Suffix + ".png");
if (saveFile.exists) saveFile.remove();
var pngOptions = new PNGSaveOptions();
pngOptions.compression = 0;
pngOptions.interlaced = false;
activeDocument.saveAs(saveFile, pngOptions, false, Extension.LOWERCASE);
doc.close(SaveOptions.DONOTSAVECHANGES);
// ==============================================================
最佳答案
即使您找到了解决方案,我也想回答您最初的问题:如何抑制对话框 - 这有时很有用。您可以通过更改 Photoshop app.displayDialogs
属性来做到这一点:
app.displayDialogs = DialogModes.NO; // no dialogs will be displayed
// your code
app.displayDialogs = DialogModes.ERROR; // default value
如果您明确想要显示 UI,也可以是 DialogModes.ALL
。
关于javascript - 在没有 'Save as..' 对话框的情况下覆盖/保存图像为 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57809945/