我有一个脚本,它检查图像是否大于250px,是否大于300px,如果这些语句中的任何一个为真,它应该调整它们的大小以适应这两个值。然后将它们保存为JPG,扩展名为large,文件名为larg。然而,我不知道如何让photoshop打开给定文件夹中的所有文件并执行脚本,也不知道如何正确导出它们,photoshop在尝试导出时停止。
这是我的代码:
// get a reference to the current (active) document and store it in a variable named "doc"
doc = app.activeDocument;
// change the color mode to RGB. Important for resizing GIFs with indexed colors, to get better results
doc.changeMode(ChangeMode.RGB);
// these are our values for the END RESULT width and height (in pixels) of our image
var fWidth = 250;
var fHeight = 300;
// do the resizing. if height > width (portrait-mode) resize based on height. otherwise, resize based on width
if (doc.height > 300) { doc.resizeImage(null,UnitValue(fHeight,"300"),null,ResampleMethod.BICUBIC); }
else if (doc.width > 250) { doc.resizeImage(null,UnitValue(fWidth,"250"),null,ResampleMethod.BICUBIC); }
// Makes the default background white
var white = new SolidColor();
white.rgb.hexValue = "FFFFFF";
app.backgroundColor = white;
// Convert the canvas size as informed above for the END RESULT app.activeDocument.resizeCanvas(UnitValue(fWidth,"px"),UnitValue(fHeight,"px"));
// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;
var newName = 'web-'+doc.name+'.jpg';
doc.exportDocument(File(doc.path+'/images/'+newName);