convert() - Media Method

The convert() method converts the image to the specified type/bit-depth. The 8-bit type is not supported, since this involves a much more complex transformation (palette selection, etc.) — instead, use reduce().

When converting images with no alpha channel, the generated alpha channel is based on the background color of the original if the background is set to transparent. Otherwise, the resulting alpha channel is solid white. You can also use the setColor() function (placed before the convert() function in the MediaScript) to set the background color, with Transparency set to true.)

Note:  convert() will convert between CMYK and CMYKA. To convert CMYK colorspace to RGB colorspace and vice versa use colorCorrect().

Syntax

convert(

RType @ <"bit-depth">

[Dither @ <value 0..10>]

[PreserveBackground @ <true, false>]

[layers @ <"layer list">] // (PSD files only)

);

Parameters

Rtype - specifies the target bit depth. Supported bit-depths are: Gray-8, RGB-15, RGB-16, RGBA-16, RGB-24, RGBA-32, CMYK-32, and CMYKA-40. The 16-bit type is 5-6-5, while the 16a-bit is 1-5-5-5 with the top bit as an alpha channel.

In addition, the following shortcuts will have default values when used as input parameters:

» Gray -> Gray-8

» RGB -> RGB-24

» RGBA -> RGBA-32

» CMYK -> CMYK-32

» CMYKA -> CMYKA-40

Note:  Deprecated parameters include: Grayscale, pal-8, 15-bit, 16-bit, 16a-bit, 24-bit, 32‑bit.

MediaRich reads up to 16-bit per channel, and automatically converts 16-bit per channel down to 8-bit per channel before operations can be handled. The Photoshop reader also converts 24-bit per channel High Dynamic Range images to 8-bits internally. Additionally, 32 bits per channel, LAB and Pantone color space are currently not supported as of the writing of this documentation.

Dither - determines the level of dithering to use for remapping image pixels to a lower bit-depth.

PreserveBackground - when dithering is used, eliminates any pixels in the source image that match the background color from the dithering process in the destination image. This can be used to eliminate fuzzy edges for an object against a solid color background.

layers - for PSD files, specifies the layers to be converted. Specify the layers to collapse and the order in which to collapse them. The layer numbers begin at 0 (background) and go up. For more information see load() - Media Method.

Example

var image = new Media();

image.load(name @ "peppers.tga");

image.convert(rtype @ "Grayscale", dither @ 5);

image.save(type @ "jpeg");