I recently dumped PhotoImpact and took the Photoshop learning curve plung... special thanks to the catalyst which was my co-workers heckling. Jerks. Don't knock it till you rock it.
I use C# on some websites to fool around with images. Cropping, resizing, filters, conversions, etc. I've coded about a dozen filters and they're okay, but not great. And they're really slow. If only I could run Photoshop filters from code...
Here's our goal:
Really, if you clicked on an article called "Automating Photoshop With C#" then you've probably got step 1 done. The only real bit of information here is that I don't know of any way to do Photoshop automation without it installed.
So if you need to run the automation on a different computer (like a server), then you'll have to install Photoshop
Wait, wrong algorithm.
Bust open your Visual Studio solution, right-click your project, and choose "Add Reference...".
Choose the COM tab, then choose the following & click "OK".
Adobe Photoshop CS5 Object Library
Adobe Photoshop CS5 Type Library
You might have CS3 or CS4 if you're behind the times. You may also have a braided belt.
public static void RunAction(string orig, string target, string action, string group)
ApplicationClass app = new ApplicationClass(); var doc = app.Open(orig); app.DoAction(action, group); var options = new BMPSaveOptions(); doc.SaveAs(target, options, true, PsExtensionType.psLowercase); doc.Close(PsSaveOptions.psDoNotSaveChanges);
Here's how I run the code:
@"C:\Projects\TestPhotoshop\TestPhotoshop\bin\Debug\original.bmp", @"C:\Projects\TestPhotoshop\TestPhotoshop\bin\Debug\new.bmp", "Sepia", "Default");
In the target path, I'm giving the file a "bmp" extension. This does not indicate that Photoshop should save it as a Bitmap. In fact, Photoshop will completely ignore the extension.
It determines the new filetype according to the "options" parameter passed into the SaveAs method. In this example, it's a BMPSaveOptions class, but you could use PNGSaveOptions for .png or use PhotoshopSaveOptions for .psd
Each of these classes has format specific properties like compression, palette, etc.
The action name and action group are literally the name of the action shown in Photoshop and the name of its folder. We used "Sepia" and "Default" in our example:
Obviously your use case isn't exactly the same as mine, so feel empowered to mess with this script.
I haven't found any excellent documentation, but if I do I'll post it.