我有一个脚本试图:
BridgeTalk
对象将所有图像发送到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)
语句似乎没有多大效果,因为错误仍在发生.
发布于 2012-07-16 12:10:30
因此,我错误地假设类型强制将适用于单位值,但当然不会,因为“像素”不是默认的Javascript类型。
在不将new UnitValue
应用于普通var ratio
的情况下,比率被强制输入为Number
(尽管currentWidth
是用“象素”单元类型实例化)。此外,var newWidth
仍是一种类似于普通Number
的产品。
下面是修正后的代码,从var currentWidth
行开始,以resizeCanvas
结尾:
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 = new UnitValue(600, "px"); /* defining the desired exported image width here */
var ratio = new UnitValue(newWidth / currentWidth, "px");
var newHeight = new UnitValue(ratio * currentHeight, "px"); /* 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(newWidth, newHeight); /* (width, height) */
photoshopDoc.resizeCanvas(newWidth, newHeight); /* (width, height) */
此外,我还得到了参数的方法,更好的resizeImage
和更好的resizeCanvas
反向!这两种方法都是正确的顺序:(width, height)
。
-感谢马克为我指明了正确的方向。
https://stackoverflow.com/questions/11478651
复制