exportDocument() '目标文件夹不存在'错误

发布于 2024-10-10 07:25:32 字数 587 浏览 4 评论 0原文

我正在尝试在 Photoshop 中制作一个脚本,该脚本将修改一些图层并将它们导出为 PNG 图像。我从其他地方复制了以下代码:

function SavePNG(saveFile){
    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = true; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(saveFile,ExportType.SAVEFORWEB,pngOpts);
}

该函数将photoshop的活动文档导出到saveFile参数指定的文件中。

它可以很好地处理“C:\images\result.png”等简单路径,但是当尝试使用“~/Desktop/”等不同路径或具有某些特殊字符的路径时,文件不会导出,并且“目标文件夹不会”存在”错误消息出现。

知道如何解决吗?

I'm trying to make a script in photoshop that will modify some layers and than export them as a PNG image. I've copied the following code from another place:

function SavePNG(saveFile){
    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = true; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(saveFile,ExportType.SAVEFORWEB,pngOpts);
}

The function export the active document of photoshop to the file specified by the saveFile parameter.

It's working fine with simple paths like "C:\images\result.png" but when trying with different paths like "~/Desktop/" or paths with some special characters the file isn't exported, and a "destination folder does not exist" error message appears.

Any idea how can I solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

老子叫无熙 2024-10-17 07:25:32

好吧,我不确定为什么会发生这种情况,但您可以尝试以下修改:

function SavePNG(saveFile){
    var tmpFile = "./tmp.png";
    tmpFile = new File(tmpFile);
    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = true; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(tmpFile,ExportType.SAVEFORWEB,pngOpts); 
    tmpFile.rename (saveFile);
    tmpFile.changePath(saveFile);
}

它将文件导出到临时文件中,然后重命名&将其移动到请求的路径,应该可以解决路径问题。

Well, I'm not sure why this is occur but you could try the following modification:

function SavePNG(saveFile){
    var tmpFile = "./tmp.png";
    tmpFile = new File(tmpFile);
    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = true; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(tmpFile,ExportType.SAVEFORWEB,pngOpts); 
    tmpFile.rename (saveFile);
    tmpFile.changePath(saveFile);
}

it'll export the file into a temporary file and then rename & move it to the requested path, should solve the path problem.

新一帅帅 2024-10-17 07:25:32

exportDocument 需要完整的文件名,而不是文件夹路径。

这有效:

activeDocument.exportDocument(new File("~/foo/foo.png"), ExportType.SAVEFORWEB, pngOpts);

这不起作用并给出“目标文件夹不存在”错误消息:

activeDocument.exportDocument(new File("~/foo/"), ExportType.SAVEFORWEB, pngOpts);

exportDocument expects a full file name, not a folder path.

This works:

activeDocument.exportDocument(new File("~/foo/foo.png"), ExportType.SAVEFORWEB, pngOpts);

This doesn't work and gives the 'destination folder does not exist' error message:

activeDocument.exportDocument(new File("~/foo/"), ExportType.SAVEFORWEB, pngOpts);
冷…雨湿花 2024-10-17 07:25:32

对于遇到此错误并且未使用 photoshop-script 的人。

该错误可能未绑定到目标文件夹,但由于用于导出步骤的文件夹被删除而发生。因此,要么

  • 重新创建录制期间使用的文件夹,要么
  • 重新创建导出步骤

For people having this error and not using photoshop-script.

The error might be unbound to the destination folder, but occurs because the folder, which was used for the export step, is deleted. So either

  • recreate the folder, which was used during recording, or
  • recreate the export step
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文