# Color Quantization

Functions for truecolor to palette conversion

Summary

Color Quantization | Functions for truecolor to palette conversion
Functions |
gdImageTrueColorToPaletteSetMethod | Selects the quantization method
gdImageTrueColorToPaletteSetQuality | Chooses a quality range for quantization
gdImageCreatePaletteFromTrueColor | Creates a new palette image from a truecolor image
gdImageTrueColorToPalette | Converts 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

im | The image.
method | The quantization method, see gdPaletteQuantizationMethod.
speed | The 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

### 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

im | The image.
min_quality | The 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_quality | The 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

im | The image.
dither | Whether dithering should be applied.
colorsWanted | The number of desired palette entries.

#### Returns

A newly create palette image; NULL on failure.

#### See also

- gdImageCreatePaletteFromTrueColor
- gdImageTrueColorToPaletteSetMethod
- gdImageNeuQuant

### gdImageTrueColorToPalette

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

Converts a truecolor image to a palette image

#### Parameters

im | The image.
dither | Whether dithering should be applied.
colorsWanted | The number of desired palette entries.

#### Returns

Non-zero if the conversion succeeded, zero otherwise.

#### See also

- gdImageCreatePaletteFromTrueColor
- gdImageTrueColorToPaletteSetMethod
- gdImagePaletteToTrueColor

> 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