gpt4 book ai didi

image-processing - Photoshop/InDesign CS5 脚本 : image size conversion error is using too much memory?

转载 作者:行者123 更新时间:2023-12-03 07:51:01 26 4
gpt4 key购买 nike

我有一个脚本试图:

  • scan an InDesign document for all images
  • send all images to Photoshop via the  BridgeTalk  object
  • resize all of the images to 600px width (maintaining aspect-ratio mathematically)
  • export all of the images from Photoshop to a new folder


似乎我可能需要以编程方式调整每张图像的 DPI,因为在调整一张图像大小之前 Photoshop 就崩溃了。该错误表明此脚本使临时内存过载,我认为它与图像质量和/或大小有关...这是错误消息:

General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
Error in Line 1:
Could not complete the command because the scratch disks are full.



这是转换图像大小的相关代码:
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)似乎没有太大影响,因为错误仍在发生......

最佳答案

所以,我错误地假设类型强制将适用于单位值,但当然它不会因为“像素”不是默认的 Javascript 类型。

不申请 new UnitValuevar ratio , 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) */

另外,我得到了方法的参数 resizeImageresizeCanvas向后!这是两者的正确顺序: (width, height) .

-- 感谢@Mark 为我指明了正确的方向。

关于image-processing - Photoshop/InDesign CS5 脚本 : image size conversion error is using too much memory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11478651/

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