Color Quantization

Functions for truecolor to palette conversion

Summary
Color QuantizationFunctions for truecolor to palette conversion
Functions
gdImageTrueColorToPaletteSetMethodSelects the quantization method
gdImageTrueColorToPaletteSetQualityChooses a quality range for quantization
gdImageCreatePaletteFromTrueColorCreates a new palette image from a truecolor image
gdImageTrueColorToPaletteConverts a truecolor image to a palette image

Functions

gdImageTrueColorToPaletteSetMethod

int gdImageTrueColorToPaletteSetMethod (gdImagePtr im,
int method,
int speed)

Selects the quantization method

That quantization method is used for all subsequent gdImageTrueColorToPalette and gdImageCreatePaletteFromTrueColor calls.

Parameters

imThe image.
methodThe quantization method, see gdPaletteQuantizationMethod.
speedThe quantization speed between 1 (highest quality) and 10 (fastest).  0 selects a method-specific default (recommended).

Returns

Zero if the given method is invalid or not available; non-zero otherwise.

See also

gdImageTrueColorToPaletteSetQuality

void gdImageTrueColorToPaletteSetQuality (gdImagePtr im,
int min_quality,
int max_quality)

Chooses a quality range for quantization

That quality range is used in all subsequent calls to gdImageTrueColorToPalette and gdImageCreatePaletteFromTrueColor if the quantization method is GD_QUANT_LIQ.

Parameters

imThe image.
min_qualityThe minimum quality in range 1-100 (1 = ugly, 100 = perfect).  If the palette cannot represent the image with at least min_quality, then no conversion is done.
max_qualityThe maximum quality in range 1-100 (1 = ugly, 100 = perfect), which must be higher than the min_quality.  If the palette can represent the image with a quality better than max_quality, then fewer colors than requested will be used.

gdImageCreatePaletteFromTrueColor

gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im,
int dither,
int colorsWanted)

Creates a new palette image from a truecolor image

Parameters

imThe image.
ditherWhether dithering should be applied.
colorsWantedThe number of desired palette entries.

Returns

A newly create palette image; NULL on failure.

See also

gdImageTrueColorToPalette

int gdImageTrueColorToPalette (gdImagePtr im,
int dither,
int colorsWanted)

Converts a truecolor image to a palette image

Parameters

imThe image.
ditherWhether dithering should be applied.
colorsWantedThe number of desired palette entries.

Returns

Non-zero if the conversion succeeded, zero otherwise.

See also

int gdImageTrueColorToPaletteSetMethod (gdImagePtr im,
int method,
int speed)
Selects the quantization method
void gdImageTrueColorToPaletteSetQuality (gdImagePtr im,
int min_quality,
int max_quality)
Chooses a quality range for quantization
gdImagePtr gdImageCreatePaletteFromTrueColor (gdImagePtr im,
int dither,
int colorsWanted)
Creates a new palette image from a truecolor image
int gdImageTrueColorToPalette (gdImagePtr im,
int dither,
int colorsWanted)
Converts a truecolor image to a palette image
A combination of algorithms used in libimagequant aiming for the highest quality at cost of speed.
gdImagePtr gdImageNeuQuant(gdImagePtr im,
const int max_color,
int sample_factor)
Creates a new palette image from a truecolor image
int gdImagePaletteToTrueColor(gdImagePtr src)
Convert a palette image to true color
Close