ComponentNormalizer

Scales a parsed CSS component value into the [0..1] range used by the color models.

Table of contents

Namespace: Com\Tecnick\Color

class ComponentNormalizer

Source: src/ComponentNormalizer.php:35

Scales a parsed CSS component value into the [0..1] range used by the color models. Held as a collaborator by Css.

Methods

normalize()

Get the normalized value from [0..$max] to [0..1]

A percentage string (e.g. ‘50%’) is divided by 100 and ignores $max; the ‘%’ must be the last character. Any other value is divided by $max. Non-numeric values, and any value passed with a non-positive $max, yield 0.0. The result is clamped to [0..1].

public normalize(mixed $value, int $max): float

Parameters:

  • $value (mixed): Value to convert
  • $max (int): Max input value (reference value), must be positive

Returns: float: value [0..1]

Source: src/ComponentNormalizer.php:50