using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace PSexample
{
class Program
{
static void Main(string[] args)
{
dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
Regex reg = new Regex(@"(?i)\.(jpg|jpeg)$"); //select jpg files only
//change folder to suit
var files = Directory.GetFiles(@"d:/a test", "*.*").Where(path => reg.IsMatch(path)).ToList();
app.Preferences.RulerUnits = 1; //pixels
foreach (string file in files)
{
app.open(file);
string Name = app.ActiveDocument.Name;
//resize to a width of 300 pixels with constraint
app.ActiveDocument.ResizeImage(300 /*width*/, null/*height*/, 300/*resolution*/, 5/* ResampleMethod.BICUBICSHARPER*/);
string saveFile = @"c:/utils/"+ Name;
dynamic jpgOpts = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.JPEGSaveOptions"));
jpgOpts.embedColorProfile = true;
jpgOpts.formatOptions = 1 /* FormatOptions.STANDARDBASELINE*/;
jpgOpts.matte = 1 /*MatteType.NONE*/;
jpgOpts.quality = 12; //1-12
app.ActiveDocument.SaveAs(saveFile, jpgOpts, true, 2); //2= lowercase
app.ActiveDocument.Close(2); /* Close document */
}
}
}
}