打开文件夹中的所有pdf文件并在其他文件夹中另存为调整大小的jpgs
Open all pdf files in folder and save as resized jpgs in other folder
我有一个脚本来检查图像是否宽于 250 像素以及它是否高于 300 像素,如果这些陈述中的任何一个为真,它应该调整它们的大小以适应这两个值。然后它应该将它们保存为 jpgs,扩展名为 large 到名为 large 的文件夹中的文件名。但是我不知道如何让 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);
打开 PDF 文件有点困难。正如我在几周前的请求中所描述的:
Photoshop JavaScript: options to open a PDF as smart object
我的解决方法是使用一个动作(从动作面板)打开文件(打开模式控制,以设置高效的 PDF 渲染)并启动脚本。
您可以使用该操作导出为 Web JPG。
如果要使用脚本,File
需要完整路径。
var destFile = new File ("~/Desktop/" + "web-" + doc.name + ".jpg");
还需要 exportDocument
的参数(非可选)。
doc.exportDocument(destFile, ExportType.SAVEFORWEB, options);
我有一个脚本来检查图像是否宽于 250 像素以及它是否高于 300 像素,如果这些陈述中的任何一个为真,它应该调整它们的大小以适应这两个值。然后它应该将它们保存为 jpgs,扩展名为 large 到名为 large 的文件夹中的文件名。但是我不知道如何让 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);
打开 PDF 文件有点困难。正如我在几周前的请求中所描述的: Photoshop JavaScript: options to open a PDF as smart object
我的解决方法是使用一个动作(从动作面板)打开文件(打开模式控制,以设置高效的 PDF 渲染)并启动脚本。
您可以使用该操作导出为 Web JPG。
如果要使用脚本,File
需要完整路径。
var destFile = new File ("~/Desktop/" + "web-" + doc.name + ".jpg");
还需要 exportDocument
的参数(非可选)。
doc.exportDocument(destFile, ExportType.SAVEFORWEB, options);