我对Photoshop脚本非常陌生,所以请耐心等待。
到目前为止,我有以下脚本,但我一直收到错误,我的doc对象引用无效。任何人都可以帮我正确分配我的文件,以便我可以在条件声明中使用它们吗?
还需要帮助保存文档,使其具有与现有文件名和扩展名相同的文件名和扩展名,即使文件名格式错误,例如"可怕的spaces.JPEG"
谢谢!
var inputFolder = Folder.selectDialog("Select a folder to process");
var fileList = inputFolder.getFiles("*.*"); //Use whatever extension you want or no extension to select all files
for(var i=0; i<fileList.length; i++) {
if (fileList[i] instanceof File && fileList[i].hidden == false) {
// get a reference to the new document
var doc = open(fileList[i])
}
// do the resizing. if the width of the document is already less than 500, then don't do anything. Otherwise resize too 500 wide, keep the aspect ratio, and change the resampling.
if (doc.width < "500px") {
// don't do anything
}
else {
doc.resizeImage(UnitValue(500,"px"),null,null,ResampleMethod.BICUBIC);
}
app.activeDocument.close();
}
答案 0 :(得分:2)
这是最终的工作脚本。希望这可能会帮助其他人想要使用图像宽度条件调整图像大小。谢谢!
var inputFolder = Folder.selectDialog("Select a folder to process");
var fileList = inputFolder.getFiles("*.*"); //Use whatever extension you want or no extension to select all files
for(var i=0; i<fileList.length; i++) {
open(fileList[i]);
// do the resizing. if the width of the document is already less than 500, then don't do anything. Otherwise resize to 500 wide, keep the aspect ratio, and change the resampling.
if (activeDocument.width > "500") {
activeDocument.resizeImage(UnitValue(500,"px"),null,72,ResampleMethod.BICUBIC);
app.activeDocument.save();
}
app.activeDocument.close();
}
答案 1 :(得分:1)
你是否在Extendscript工具包中运行它?确保您定位到photoshop - 否则您的app.activeDocument对象将为null。当我以photoshop为目标时,你的脚本运行正常。
要保存文档 - 如果要保存原始文件,就像在关闭文档之前调用app.activeDocument.save()一样简单。如果要将其保存到新位置,请修改下面的代码段。有关options对象的更多详细信息,请参阅photoshop安装目录中的JavaScript Ref文档。
var options = new PhotoshopSaveOptions();
options.embedColorProfile = true;
options.alphaChannels = true;
saveFile = new File( "/some/other/folder/" + app.activeDocument.name + ".psd")
app.activeDocument.saveAs(saveFile, options, false, Extension.LOWERCASE);
app.activeDocument.close();