Creating and Parsing Colors

Create concrete color values from CSS text, channels, constructors, and alpha values.

In this chapter

Read in order or jump directly to a specific page.

  1. Supported concrete color input

    Identify the concrete CSS color values PHPColor can parse, the typed object each syntax produces, and the boundary with contextual CSS.

  2. Choose text or channel input

    Choose between parsing text, normalizing an existing object, and constructing channels whose color space and numeric scale are already known.

  3. Choose an invalid-input contract

    Decide when malformed color input should raise a parsing exception, return null, or pass into a separate application policy check.

  4. Use named constructors

    Decide when a code-owned color should use a named constant and when its value should remain data.

  5. Concrete and deferred CSS colors

    Decide whether a CSS color can resolve immediately or must retain variables, currentColor, or color-scheme choices until context is available.

  6. Work with alpha values

    Choose where transparency belongs, preserve it through transformations, and serialize it without changing channel order.

  7. Choose a normalization boundary

    Decide when to preserve a parsed color space, convert into working coordinates, and serialize a stable representation for another system.

  8. Parse and find named colors

    Use CSS names as recognized input or approximate labels without confusing either role with color identity.