Skip to content

RGBAColor

Mistralys edited this page Feb 4, 2022 · 14 revisions

This utility class is used to hold information on an RGB based color, with optional opacity / alpha channel.

Overview

Supported color value ranges

  • 8-Bit integer: 0-255 (Standard color values)
  • 7-Bit integer: 0-127 (PHP GD style alpha channel)
  • Float: 0.00-1.00 (CSS opacity)
  • Percent: 0-100 (General purpose)

Color components

  • Red
  • Green
  • Blue
  • Opacity
  • Transparency (inverted opacity)

Usage examples

use AppUtils;

$color = new RGBColor

Comparing colors

Ignoring the opacity

The match() method compares two colors, ignoring the opacity.

use AppUtils;

$colorA = ColorFactory::createFromHEX('CCC');
$colorB = ColorFactory::createFromHEX('CCC');

if($colorA->matches($colorB))
{
    echo 'Colors match.';
}
else
{
    echo 'Colors do not match.';
}

Output:

Colors match.

With opacity

The matchAlpha() method compares two colors, including their opacity.

use AppUtils;

$colorA = ColorFactory::createFromHEX('CCCCCCDD');
$colorB = ColorFactory::createFromHEX('CCCCCCEE');

if($colorA->matchesAlpha($colorB))
{
    echo 'Colors match.';
}
else
{
    echo 'Colors do not match.';
}

Output:

Colors do not match.

New here?

Have a look at the overview for a list of all helper classes available in the package.

Table of contents

Find the current page in the collapsible "Pages" list above, and expand the page, to view a table of contents.

Clone this wiki locally