limitColors — Set a maximum number of colors for the current image

Description

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 (optional)

Maximum number of colors that should be retained in the color palette. Or null to convert to truecolor. Default: null

matte (optional)

A color to blend transparent pixels against. Can be defined in one of the different color formats. Default: no matte color

Return Values

Instance of Intervention\Image\Image

Examples

  1. // open PNG-32 image from file
  2. $img = Image::make('public/foo.png');
  3. // limit colors to 255 (PNG-8) blending transparency against orange
  4. $img->limitColors(255, '#ff9900');
  5. // open PNG-8 image from file
  6. $img = Image::make('public/bar.png');
  7. // convert to truecolor
  8. $img->limitColors(null);

See also