我有一个保存在某个位置的主文档。这个主文件有一个大精灵。在运行脚本时,会使用各种模式的精灵创建多个新文档。我想将这些多个新文档另存为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 - 在没有“另存为..”对话框的情况下,将图像覆盖/另存为PNG,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57809945/

10-09 17:35