javascript - 在没有 'Save as..' 对话框的情况下覆盖/保存图像为 PNG

标签 javascript photoshop photoshop-script

我有一个保存在某个位置的主文档。这份主文档有一个大 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/

相关文章:

javascript - 在 react 中过滤 geojson 的最佳方法?

javascript - for循环和remove()的细节

android - Photoshop 中 Android 和 iPhone 设计的屏幕分辨率

algorithm - 图像编辑软件中滤镜背后使用的算法是什么?

binaryfiles - 使用 Extendscript 编写二进制文件。文件大小不正确

javascript - 出现警告框后运行 Action 的 Photoshop(CC) 脚本

javascript - 正则表达式来匹配这组值

javascript - 动画结束事件未触发

image - 一种将 PSD 格式转换为 Gimp 可以读取的格式的方法

javascript - 从当前位置相对移动选择