如何解决如何使用脚本 Photoshop 保存文件?
我想编写一个脚本,将文本文件中的不同文本替换到我的 shalon 中,并将图像保存为 jpeg 格式。
此行出现错误:“此功能在此版本的 Photoshop 中可能不可用”:
activeDocument.saveAs(saveFile,jpgSaveOptions,true,Extension.LOWERCASE);
我的代码:
while(!myFile.eof)
{
line = myFile.readln();
createText(line);
var thistimestamp = Math.round(new Date().getTime() / 1000);
saveFile = new File( "/c/Users/marki/Desktop/Temp001/" +thistimestamp)
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile,saveOptions,Extension.LOWERCASE);
}
我使用 Adobe Photoshop:2017.0.0 20161012.r.53 2016/10/12:23:00:00 CL 1094006 (x64)
解决方法
您错过了扩展名:D
saveFile = new File( "c:\\temp\\" + thistimestamp) + ".jpg");
,
假设您的脚本 createFile()
定义良好且有效,您在开始发出命令之前缺少文档创建命令 app.documents.add()
。您还缺少文件打开程序。添加后,代码工作正常:
function createText(fface,size,colR,colG,colB,content,tX,tY) {
var artLayerRef = app.activeDocument.artLayers.add()
artLayerRef.kind = LayerKind.TEXT
textColor = new SolidColor();
textColor.rgb.red = colR;
textColor.rgb.green = colG;
textColor.rgb.blue = colB;
textItemRef = artLayerRef.textItem
textItemRef.font = fface;
textItemRef.contents = content;
textItemRef.color = textColor;
textItemRef.size = size
textItemRef.position = new Array(tX,tY)
}
var myFile = new File("/c/temp/myfile.txt");
myFile.open('r');
while(!myFile.eof) {
app.documents.add();
line = myFile.readln();
createText(line,10,2,line,10);
var thistimestamp = Math.round(new Date().getTime() / 1000);
saveFile = new File( "/c/temp/" +thistimestamp)
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile,saveOptions,true,Extension.LOWERCASE);
}
此代码测试版本为 20.0.2 20181219.r.30 2018/12/19: 1202136 x64
文本文件内容为:
在 Photoshop 中的结果是:
当然,这三个文件都以 jpeg 格式保存在 c:\temp 中。
如果您没有可用的 createText
函数,您可以在此 article 中找到示例。本例中的函数取自那篇文章。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。