
68 Chapter 3
•
•
•
•
Syntax
crop(
[Xs @ <pixels>, <percentage + "%">]
[Ys @ <pixels>, <percentage + "%">]
[Xo @ <left pixel>]
[Yo @ <top pixel>]
[layers @ <"layer list">] // (PSD files only)
[PadColor @ <color in hexadecimal or rgb>]
[PadIndex @ <value 0..16777215>]
[Transparency @ <value 0..255>]
[Alg @ <"Normal", "BackColor", "Color", "Alpha">]
);
Parameters
Xs and Ys - specify the size of the resulting image. The size can be specified either as an
absolute, or as a percentage of the original size (percentages must be designated by adding
the “%” as in the Syntax example). Where xs or ys is not specified, the original size is used.
Xo and Yo - specify the position of the top left of the marquee to use. Where either of these
is not specified, the marquee is centered on the image.
layers - for PSD files, specifies the layers to be cropped.The layer numbers begin at 0
(background) and go up. For more information see load() on page 101.
Padcolor or Padindex - specifies the color to be used where the new image dimensions
extend beyond the current image. If a pad color is not specified, the image’s background
color is used by default. For more information about setting an image’s background color,
see setColor() on page 131.
Transparency - specifies the transparency (255 is opaque and 0 is transparent) of the
padded area’s alpha channel. This parameter is useful when the cropped image is used in
a composite() function.
NOTE: If the cropped image is not 32-bit before cropping, the transparency information is not used
on the next composite() function.
Alg - when set to anything other than “Normal”, the area specified (or the whole image if
no area was defined) is scanned, and the area to crop shrunk accordingly:
•
“BackColor” trims away the background areas only.
•
“Color” trims away areas that match the pad color.
•
“Alpha” trims away areas with transparent alpha channels.
NOTE: Using Alg @ Alpha on an image with no alpha channel, but which has transparency on,
will give the same results as Alg @ BackColor.
Example
var image = new Media();
image.load(name @ "peppers.tga");
image.crop(xs @ 20, ys @ 16 + "%", padcolor @ 0xe0e0e0);
image.save(type @ "jpeg");