Download the PHP package domm98cz/color without Composer

On this page you can find all versions of the php package domm98cz/color. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package color

color

Build Status Latest Version PHP Version

Small color library for PHP 8.3+ with no runtime dependencies: parse hex, rgb, hsl or any CSS Color 4 color, convert between 21 color spaces, derive tints, shades and harmonies, measure contrast and write the result back for the web. Every computation names its method (space, metric, color wheel), so two tools built on it agree with each other; not released yet, so the API may still change before 1.0 (UPGRADE.md lists every change).

Install

Scope

The library is deliberately small: a Color value, conversions, notation, differences, contrast, gamut mapping, harmonies and scales for the web. It does not do ICC profiles or print/CMYK, color appearance models or HDR, color vision deficiency simulation, WCAG success-criteria evaluation (only the contrast ratio), palette optimization (changing a whole palette to meet constraints; adjusting one color to a contrast target is included), or measurements and spectra. A feature request outside this list needs an issue first, not a PR.

Quick start

The fluent layer (HexColor, RgbColor, RgbaColor, HslColor, OklchColor, CssColor) always outputs sRGB: a step that lands outside the gamut is mapped with the CSS Color 4 algorithm and recorded in trace(), never clipped silently. Every default it uses is listed in FluentConfig and can be swapped for a whole project (FluentConfig::defaults()->withLightness(LightnessModel::HslL) gives Sass-like results) or for one call. Runnable scripts for every feature below are in examples/.

Color spaces

The engine underneath the fluent layer is an immutable Color value in one of 21 built-in spaces: sRGB and linear sRGB, Display P3, A98 RGB, ProPhoto RGB, Rec. 2020, HSL, HWB, HSV, CIE XYZ D65/D50, CIE Lab/LCh D50 and D65, OKLab and OKLCh.

Conversions never clip: a wide-gamut color converted to sRGB keeps its negative or above-one channels, and toHex() refuses it with an OutOfGamutException until you map it on purpose (see Gamut mapping). A missing component (CSS none) is null in the color, behaves as zero in conversions and is carried over by interpolation, as CSS Color 4 specifies. A custom RGB space from primaries is a few lines (examples/custom-space.php).

Notation

Color::parse() reads everything CSS Color 4 and 5 can write, including relative colors and color-mix() (results below as written by toCss(new CssFormat(4))):

toCss() keeps out-of-gamut values; toHex() quantizes to 8 bits and is the only writer that refuses a color outside sRGB. JSON is lossless and versioned, so it is the format to store a color in.

Harmonies and color wheels

There is no single "complementary color": the wheel decides, so every harmony takes one explicitly.

On the OKLCh wheel the complement of #3366cc lies outside sRGB: the engine reports it through $member->inGamut and keeps the unclipped color, while the fluent complement() maps it to #916300. Analogous, split-complementary, tetradic, square and custom offset schemes follow the same shape.

Tints, shades, scales

Lightness steps that fall outside sRGB are mapped with the mapper you pass and listed in mappedSteps(), so a design-system scale shows which of its colors are not what was asked for. The nearest named color is found by an explicit metric; a ΔE00 above roughly 2.3 is a visible difference, so check ->difference->value before showing the name to a user.

Contrast

The ratio is never rounded: #777 on white is 4.478, which fails the 4.5:1 threshold that a rounded "4.5" would pass. Only the ratio is computed; WCAG success criteria (text size, UI components) are the caller's decision. A translucent background throws MissingBackdropException until you say what is behind it (LayerStack::of($overlay)->over($page)). The fluent isDark() uses the same WCAG relative luminance with a 0.179 threshold, the point at which black and white text reach equal contrast.

To get a color that reaches a ratio, move it along its lightness instead of guessing:

Hue and chroma are kept and only the lightness moves, in the model you name (OKLCh here); every candidate is mapped into sRGB and quantized to 8 bits, so the ratio reported is the ratio of the hex you write out. The passing candidate nearest to the input wins. A target no lightness can reach is not an error: the best candidate comes back with reachable = false and a contrast-target-unreachable warning (#3366cc on #767676 cannot reach 7:1 in either direction). The target is a plain number; what 4.5, 7 or 3 mean for your text size remains your decision.

Gamut mapping

Mapping is explicit in the engine and never happens as a side effect of a conversion. cssColor4() is the binary search in OKLCh from CSS Color 4; ray trace, chroma reduction and plain clipping are available under the same GamutMapper interface for when you need to match another tool.

Color difference

The metric is always named, because the three scales are not comparable: a ΔEOK of 0.016 and a ΔE00 of 1.84 describe the same pair. Each result carries the algorithm identity with its revision (ciede2000[kL=1,kC=1,kH=1,white=D50]@r1); any change of a computed value bumps that revision and is listed in CHANGELOG.md.

Extending

Every method the library uses is an interface you can implement: ColorSpace, HueWheel, ColorDifferenceMetric, ContrastAlgorithm, GamutMapper, TransferFunction and ChromaticAdaptationTransform (Bradford is the default adaptation between D65 and D50). A custom implementation plugs into the same services and results as the built-in ones, so a project-specific wheel or metric gets harmonies, scales and palette analysis for free.

From 1.0 the public API is everything in src/ outside *\Internal\* and without @internal, including parameter names, enum values and numeric results; tests/Unit/Architecture/public-api.txt makes every change visible in review.

Contributing / running tests

See CONTRIBUTING.md. The library supports PHP 8.3 through 8.5; CI runs the unit, conformance, property and examples suites on 8.3, 8.4 and 8.5, plus a prefer-lowest job on PHP 8.3, and PHPStan and PHP-CS-Fixer on 8.4.


All versions of color with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3 <8.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package domm98cz/color contains the following files

Loading the files please wait ...