STEP 1 Find an Image with Alpha Channels
As you may know, an alpha channel is an extra grayscale plate that lets you save a selection or mask along with an image. A single complex mask may require the creation of several alpha channels. Our sample is a real-world masking example from my book Adobe Photoshop CS2 One-on-One. First we see the original image; next we see the masked foreground set against a different background, with wispy hair and translucent flame blended to perfection. On the right, the Channels palette shows close to a dozen alpha channels, each of which represents a step in the masking process.
PHOTO CREDIT: ©ISTOCKPHOTO/ANDRZEJ BURAK
STEP 2 Define Your Problem
STEP 3 Start the ExtendScript Toolkit Utility
STEP 4 Add a Few Introductory Comments
We started our script with the copyright statement, author credits, and description shown below.
// Copyright 2006 Type & Graphics, Inc.
// Deke and Daniel McClelland, authors of this little honey
This script deletes all alpha channels from an image.
STEP 5 Target the Script on Photoshop
Now press Return (PC: Enter) twice, then enter the above lines of code. The two lines that begin // are comments. The others (which you must enter exactly as written) switch the operating system’s attention to Photoshop and make Photoshop the active application, in that order. While not absolutely necessary, this code ensures that the script works even when called from another program.
// enable double-clicking from the Macintosh Finder or the Windows Explorer
// in case we double clicked the file
STEP 7 Check Out the Channels Class
Click on the Channel class. Notice the Methods, which are the things we can do to the channels. The Channel class has delete, for deleting a single channel. The Channels class has removeAll, for deleting all channels. That’s the one we want.
STEP 8 Set a Variable for the Open Image
Note that the variable is not a comment; it’s a line of code, so accuracy is imperative! (Don’t worry about the formatting; ExtendScript Toolkit automatically makes the word var bold.)
var theImage = app.activeDocument;
STEP 9 Enter the Code That Deletes the Channels
Press Return (PC: Enter) to advance to the next line of code and enter the above. Again, for this code to work, you must enter it exactly as written. The code tells Photoshop to turn its attention to the frontmost open image, look at the file’s channels, and delete all channels that aren’t absolutely necessary to render the composite color image. This means all alpha and spot-color channels, if any exist.
STEP 10 Play the Script from ExtendScript Toolkit
Now it’s time to play the script and make sure it works. Confirm that you have an image open in Photoshop that contains lots of alpha channels. Bring up the Channels palette to track the script’s progress. Return to the ExtendScript Toolkit utility and click the Run icon (sideways triangle) at the top of the window. This plays the script in Photoshop.
If necessary, switch to Photoshop. (ExtendScript Toolkit doesn’t always do this automatically.) Then watch as Photoshop deletes each and every alpha channel.
If something goes wrong, check your code for accuracy and try again.
STEP 1 Install the Script into Photoshop CS2
STEP 2 Restart Photoshop
Photoshop loads new scripts in the Presets:Scripts folder each time you launch the program, so a restart is needed. Choose Photoshop>Quit Photoshop (PC: File>Exit). Don’t bother saving the changes to the file that formerly contained the alpha channels; you’ll need all those alpha channels in just a moment. Now start up Photoshop and open the image that contains the slew of alpha channels. Our restored image is shown here.
Go to the File>Scripts submenu and notice the appearance of a new command, Delete All Alphas. Make sure the Channels palette is visible, then choose the Delete All Alphas command. Photoshop will delete all non-color channels.
Bear in mind, this tiny 15-line script represents the most basic foray into the world of scripting in Photoshop CS2. For more information, take a look at the contents of the Scripting Guide folder that ships with Photoshop.