
58 Chapter 3
•
•
•
•
Parameters
layers - specifies the layers to collapse and the order in which to collapse them. The layer
numbers begin at 0 (background) and go up. The default collapses all layers from bottom
to top.
The layer list must be contained in quotes and consists of comma-separated entries. You
can specify ranges (“0-2”) or individual layers (“0,2”). If you specify the layers out of order,
and they are composited accordingly.
NOTE: When you specify a comma-separated list of layers, do not leave any spaces after the
commas.
If the Photoshop file has named layers, you can use the layer names (up to 31 characters)
in place of layer numbers. You can also use the “*” as a wildcard when specifying layers.
For example:
image.collapse(layers @ "B*")
This line of script collapses all layers whose names begin with “B” (such as Boy, Baseball,
Ballcap, and so on). The layers command is case-sensitive, so the example line of script will
not flip layers that begin with a lowercase “b”.
PreserveAlpha - when set to true, preserves the alpha channel of the target image layers
as the alpha channel of the resulting collapsed image. The default is false.
IgnoreAlpha - when set to true, the alpha channel information is ignored when
collapsing the image layers. The default is false.
VisibleOnly - when set to “true”, only the layers designated as visible are included in
the collapsed image. The default is false.
likePS - if set to “true”, performs the collapse like Photoshop: The default background
color is white, and the alpha channel is determined by the first layer specified for the
collapse. The default is false.
NOTE: Because likePS uses a white background color, this parameter should be disabled for
images that will later be used as a brush.
Example
var image = new Media();
image.load(name @ "pasta.psd");
image.collapse(layers @ "0-2", likePS @ true);
image.save(type @ "jpeg");