【问题标题】:Photoshop scripting, resize if image width is greater than XPhotoshop 脚本,如果图像宽度大于 X,则调整大小
【发布时间】:2016-12-22 18:45:32
【问题描述】:

我是 Photoshop 脚本的新手,所以请多多包涵。

到目前为止,我有以下脚本,但我不断收到我的 doc 对象引用无效的错误。任何人都可以帮助我正确分配我的文件,以便我可以在我的条件语句中使用它们吗?

还需要帮助以与现有文件名和扩展名相同的文件名和扩展名保存文档,即即使文件名的格式非常糟糕,如“horrible 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();

}

【问题讨论】:

  • 快速猜测...将"500px"更改为500
  • 不,这没有任何区别。同样的错误。

标签: image-processing photoshop


【解决方案1】:

这是最终的工作脚本。希望这可以帮助其他希望使用图像宽度条件调整图像大小的人。谢谢!

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();
}

【讨论】:

    【解决方案2】:

    您是否在 Extendscript 工具包中运行它?确保您的目标是 Photoshop - 否则您的 app.activeDocument 对象将为空。当我以 Photoshop 为目标时,您的脚本运行良好。

    保存文档 - 如果您想保存原始文档,只需在关闭文档之前调用 app.activeDocument.save() 即可。如果要保存到新位置,修改下面的sn-p。有关选项对象的更多详细信息,请参阅您的 photoshop 安装目录中的 JavaScript 参考文档。

    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();
    

    【讨论】:

      猜你喜欢
      • 2016-02-29
      • 2012-10-01
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 2018-06-23
      • 2013-04-28
      • 2011-12-25
      • 1970-01-01
      相关资源
      最近更新 更多