我正在尝试为Photoshop创建一个脚本,用于按不同的宽度调整打开的图像大小。目标是在每次调整大小后,将图像恢复到原始状态并运行不同的宽度。有一些在线脚本几乎可以做到这一点,但我只得到错误。我得到的错误是“未定义的对象”。
我目前有以下脚本,但我卡住了:
我目前有以下脚本,但我卡住了:
// get a reference to the current (active) document and store it in a variable named "doc"
doc = app.activeDocument;
// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 940;
// our web export optionsvar options = new ExportOptionsSaveForWeb();
function SaveJPEG(saveFile, quality) {
var exportOptionsSaveForWeb = new ExportOptionsSaveForWeb();
exportOptionsSaveForWeb.format = SaveDocumentType.JPEG;
exportOptionsSaveForWeb.includeProfile = false;
exportOptionsSaveForWeb.interlaced = false;
exportOptionsSaveForWeb.optimized = true;
exportOptionsSaveForWeb.quality = 80;
}
var newName = 'F' + doc.name + '.jpg';
doc.exportDocument(File(doc.path + '/' + newName), ExportType.SAVEFORWEB, options);
doc.activeHistoryState = doc.historyStates.index(0);
未定义的错误导致脚本在var newName行停止。需要说明的是,这是针对Photoshop CS6的。
非常感谢您的任何帮助。
app.activeDocument
未定义。是documents.length != 0
吗?(来自Photoshop scripting: app.activeDocument is undefined) - Andrew Mortondoc = app.activeDocument;
进行赋值并没有问题,只是它可能会有一个undefined
的值。因此,当你尝试获取doc.name
时会失败,因为undefined
没有.name
属性。你是否检查了documents.length
? - Andrew Morton