Image Processing Script
Hi everybody,
this is what I need to do:
All image files from my input folder must be converted to JPEG, RGB, 72dpi and 234 Pixels in width or height.
Source files are TIFF, JPEG or EPS files.
I do not know much about scripting, but I searched the Internet for my purposes and built the follwing script from my search results:
// main settings
var picSourcePath = "C:\\Users\\nolte\\Desktop\\Originale\\";
var picTargetPath = "C:\\Users\\nolte\\Desktop\\Ausgang\\";
var maxSize = 234; // max width and height
//###################################################################################
// save settings and customize environment
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
var startDisplayDialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
//var doc = app.activeDocument;
var picFolder = Folder(picSourcePath);
var fileList = picFolder.getFiles();
if (picSourcePath != null && picTargetPath != null) {
for (var i=0; i<fileList.length; i++) {
if (fileList instanceof File) {
open(fileList);
var newFileName = fileList.name;
app.activeDocument.changeMode(ChangeMode.RGB);
{
// resize
resize(maxSize);
//if (confirm('Sharpen?')) {
// app.activeDocument.activeLayer.applySharpen();
//}
//if (confirm('Save and Close?')) {
saveWebJpg(newFileName.substring(0, newFileName.length-4) + ".jpg", picTargetPath, 100);
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
//}
}
// ... and close at all events
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
// restore settings
app.preferences.rulerUnits = startRulerUnits;
app.preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
// Funktion um Dokument als Jpeg zu speichern (Fuer Web speichern...)
// Parameter: Dateiname, Pfad mit abschliessendem '\'!, Qualitaet 1-100
function saveWebJpg(jpgName, filePath, jpgQuality ) {
var saveFile = new File(filePath + jpgName);
var webJpgOptions = new ExportOptionsSaveForWeb();
webJpgOptions.format = SaveDocumentType.JPEG;
webJpgOptions.optimized = true;
webJpgOptions.quality = jpgQuality;
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, webJpgOptions);
File = null; ExportOptionsSaveForWeb = null;
}
function resize(size)
{
if(app.activeDocument.width > app.activeDocument.height)
app.activeDocument.resizeImage(size, (size * app.activeDocument.height/app.activeDocument.width),null, ResampleMethod.BICUBIC);
else
app.activeDocument.resizeImage((size * app.activeDocument.width/app.activeDocument.height), size, null, ResampleMethod.BICUBIC);
}
The script works fine for JPEG, TIFF and pixel EPS files. The only problem occurs with vector EPS files.
Photoshop opens vector EPS files in low resolution (72dpi), then my script exports these files with the "Save as Web JPG" settings. The output quality of the processed pictures is really bad.
I found out, that there is an "epsOpenOptions" command for Photoshop scripting. I tried to build the following code into my script in order to force Photoshop to open vector EPS files with an resolution of 300dpi. Then the rest of my script shall export these according to my specifications.
// Create a EPS option object [height & width are doc size]
var epsOpenOptions = new EPSOpenOptions
epsOpenOptions.antiAlias = true
epsOpenOptions.mode = OpenDocumentMode.RGB
epsOpenOptions.resolution = 300
epsOpenOptions.page = 3
epsOpenOptions.constrainProportions = true
However, I cannot get this to work and I don't know where I'm wrong. Can anybody help me to modify my script, so that only EPS files will be opened with these options and all other files will be opened as they are?
Thanks in advance!
