---
application: "Intervention Image"
version: "Version 2"
status: "eol"
---

# Image::limitColors

## Reduce number of colors for the current image



> public Intervention\Image\Image limitColors(integer $count, [mixed $matte])

Method converts the existing colors of the current image into a color table with a given maximum **count** of colors. The function preserves as much alpha channel information as possible and blends transarent pixels against a optional **matte color**.

### Parameters

#### count
Maximum number of colors that should be retained in the color palette. Or `null` to convert to truecolor.

#### matte (optional)
A color to blend transparent pixels against. Can be defined in one of the different [color formats](https://image.intervention.io/v2/getting-started/formats.md). Default: no matte color

### Return Values
Instance of `Intervention\Image\Image`

### Examples

```php
// open PNG-32 image from file
$img = Image::make('public/foo.png');

// limit colors to 255 (PNG-8) blending transparency against orange
$img->limitColors(255, '#ff9900');
```

### See also

- [save](https://image.intervention.io/v2/api/save.md)
- [encode](https://image.intervention.io/v2/api/encode.md)

---

## Become a Sponsor

### Intervention Image needs your help to keep the project going

Intervention Image is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)