Extending Photoshop and Fireworks

The current project I am working on at work involves a shit load of assets rendered with a 3D program. I had over 430 Targa images with an alpha channel that needed to have that channel applied, trimmed, saved out as a 32-bit PNG, then taken in to Fireworks to be exported as an 8-bit PNG with alpha transparency.

Not only that, but I had PSD's that contained basically 2 layer groups and a background layer. I needed to save out a JPG for every combination of layers in those 2 groups. It will turn out to be almost 800 JPG's!

Now I could have done all this by hand, but A, I really didnt want to, and B, it would probably take me a full week to do it. And then what happens if we need to change something on one of the images, or save them out with different compression?

As soon as I received all these assets, I knew this would be the perfect opportunity to explore the scripting capabilities of both Photoshop and Fireworks. Both programs provide a JavaScript API that gives you access to open document DOM's, the OS's file system, and just about every command and tool available. If you have some time to spare, I highly suggest checking out the documentation for both programs. It can save you a lot of work.

The Photoshop JavaScript API is without a doubt wonderful. Its powerful, well documented, seems well thought out, and, if you are familiar with JavaScript, is rather easy to figure out. Within a matter of hours, I was able to write a script to do exactly what I needed to do. References guides (pdf format) are included in your Photoshop install under Program Files\Adobe\Adobe Photoshop CS2\Scripting Guide\.

The Fireworks API, while equally powerful, was a bit more difficult to get the hang of. The documentation is sparse, and the lack of examples is a little frustrating at times. It took me much longer to write a script that accomplished a seemingly simpler task. The most frustration came from an error in the scripting documentation. It states that paletteTransparencyType is a property of an ExportOptions object that can be set to "none", "index", "index alpha", or "rgba". After a few hours of trouble shooting and a lot of head scratching, I used the "Save as Command" command in the history palette to look at the JS generated by Fireworks itself. So yeah....there is no paletteTransparencyType. It is in fact just paletteTransparency. After figuring that out, everything ran smoothly.