Color Formats

Intervention Image supports four ways to define colors for its methods.

Integer Format

By default the pickColor method returns the RGB value as integer. You can also pass a color in this format to all other methods.

Examples

  1. // pick color and fill image
  2. $color = Image::make('public/foo.jpg')->pickColor(10, 10);
  3. $img->fill($color);
  4. // pass colors of the GD Library
  5. $im = imagecreatefrompng('public/foo.jpg');
  6. $rgb = imagecolorat($im, 10, 15);
  7. $img->fill($rgb);

Array Format

Pass the RGB integers of a color as a PHP array with or without an alpha value between 1 (opaque) and 0 (full transparency).

Examples

  1. // color in array format
  2. $img->fill(array(255, 0, 0));
  3. // color in array format with alpha value
  4. $img->fill(array(255, 255, 255, 0.5));

Hexadecimal Format

You can pass colors as a hex triplet used normally in HTML and CSS. It’s possible to use six-digit format as well as the shorthand form.

Examples

  1. // shorthand hex color
  2. $img->fill('#ccc');
  3. // six-digit hex color
  4. $img->fill('#cccccc');
  5. // works without prefix
  6. $img->fill('cccccc');

RGB & RGBA string format

RGB string values in functional notations are also supported. If you want to include an alpha value use the RGBA format like in the following example.

Examples

  1. // rgb color value in integer range
  2. $img->fill('rgb(255, 0, 0)');
  3. // rgba color value with alpha
  4. $img->fill('rgba(255, 0, 0, 1)');
  5. // rgba color value with transparent alpha
  6. $img->fill('rgba(0, 0, 0, 0.5)');