我有一个脚本试图:
- 扫描 InDesign 文档中的所有图像
BridgeTalk
通过对象将所有图像发送到 Photoshop- 将所有图像的大小调整为 600px 宽度(在数学上保持纵横比)
- 将所有图像从 Photoshop 导出到新文件夹
似乎我可能需要以编程方式调整每张图像的 DPI,因为在调整一张图像大小之前 Photoshop 就崩溃了。该错误表明此脚本使临时内存过载,我认为它与图像质量和/或大小有关...这是错误消息:
发生一般 Photoshop 错误。此功能在此版本的 Photoshop 中可能不可用。
第 1 行中的错误:
由于暂存盘已满,无法完成命令。
这是转换图像大小的相关代码:
function resaveInPS(imagePaths, imagesFolder)
{
/*
* NOTE: no single-line comments are allowed in this function, because it is not read line-by-line by BridgeTalk, but as a single String;
* only multi-line comments will work, because they are terminated at each end
*/
BridgeTalk.bringToFront("photoshop"); /* switch view from InDesign to Photoshop */
app.displayDialogs = DialogModes.NO; /* Photoshop statement, prevents status alerts from interrupting */
var imagePath = "";
var fileName = "";
var largerImage = "";
for(var i = 0; i < imagePaths.length; i++)
{
imagePath = imagePaths[i].fullName;
fileName = imagePaths[i].name;
largerImage = fileName.substr(0, fileName.length - 4); /* getting rid of the file extension: Photoshop will handle the file extension */
var photoshopDoc = "";
photoshopDoc = app.open(new File(imagePath) );
var currentWidth = photoshopDoc.width; /* in inches */
var currentHeight = photoshopDoc.height; /* in inches */
currentWidth.convert("px"); /* now in pixels */
currentHeight.convert("px"); /* now in pixels */
var newWidth = 600; /* defining the desired exported image width here */
var ratio = newWidth / currentWidth;
var newHeight = ratio * currentHeight; /* maintaining aspect ratio of the resized image's height here */
alert("The currentHeight is " + currentHeight + ".\n\nThe ratio is " + ratio + ".\n\nThe newHeight is " + newHeight + ".");
photoshopDoc.resizeImage(newHeight, newWidth); /* (height, width) */
photoshopDoc.resizeCanvas(newHeight, newWidth); /* (height, width) */
var saveOptions = new TiffSaveOptions(); /* handling the file extension here */
photoshopDoc.saveAs(new File(imagesFolder + "/" + largerImage), saveOptions); /* saving the new image in the folder here, with the file extension */
photoshopDoc.close(SaveOptions.DONOTSAVECHANGES); /* close the Photoshop document without saving */
app.purge(PurgeTarget.ALLCACHES); /* clears the clipboard, history, and undo cache in Photoshop; Note: does NOT delete the temporary files! */
} /* end of for loop */
app.displayDialogs = DialogModes.ALL; /* resume normal dialogs after saving the file and closing the document */
app.purge(PurgeTarget.ALLCACHES); /* clears the clipboard, history and undo cache in Photoshop; Note: does NOT delete the temporary files! */
} // end of function ResaveInPS
注意 ——我对该语句的使用 app.purge(PurgeTarget.ALLCACHES)
似乎没有太大影响,因为错误仍在发生......