gpt4 book ai didi

image-processing - Photoshop 脚本,如果图像宽度大于 X,则调整大小

转载 作者:行者123 更新时间:2023-12-04 08:28:54 25 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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

关于image-processing - Photoshop 脚本,如果图像宽度大于 X,则调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28645483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com