Download the PHP package tecnickcom/tc-lib-color without Composer

On this page you can find all versions of the php package tecnickcom/tc-lib-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 tc-lib-color

tc-lib-color

PHP library to manipulate various color representations.

Latest Stable Version Build Coverage License Downloads

Sponsor on GitHub

💖 Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance →


Overview

tc-lib-color parses, converts and formats the color values used in web and PDF output.

Namespace \Com\Tecnick\Color
Author Nicola Asuni [email protected]
License GNU LGPL v3 - see LICENSE
API docs https://tcpdf.org/docs/srcdoc/tc-lib-color
Packagist https://packagist.org/packages/tecnickcom/tc-lib-color

Features

Color Models

Integration Helpers


Requirements


Installation


Quick Start

Any supported notation can be parsed through the same entry point:

getCssColor() emits a value that getColorObj() parses back to the same color.

Supported color notations

Notation Examples
Hexadecimal #RGB, #RGBA, #RRGGBB, #RRGGBBAA
Name steelblue, color.steelblue, transparent
Gray g(128), g(50%)
RGB rgb(51,102,153), rgb(20% 40% 60%), rgba(51,102,153,0.85), rgb(51 102 153 / 85%)
HSL hsl(210,50%,40%), hsl(210deg 50% 40%), hsla(210,50%,40%,0.85)
CMYK cmyk(67%,33%,0%,40%), cmyka(67,33,0,40,0.85)
CIE Lab lab(41% -2 -25), lab(41 -2 -25 / 0.85)
Acrobat JavaScript ["T"], ["G",0.5], ["RGB",0.2,0.4,0.6], ["CMYK",0.67,0.33,0,0.4]

Components are separated either by commas or by spaces, not by a mixture of the two, and the alpha channel by a comma in the first form or by a slash in the second. A hue accepts the CSS angle units (deg, grad, rad, turn). Out-of-range values are clamped and a hue wraps, as CSS Color Level 4 requires, so rgb(-10,0,0) is black and hsl(-150,50%,50%) is the same as hsl(210,50%,50%). Anything else is rejected with a Com\Tecnick\Color\Exception.

g(), cmyk() and cmyka() are notations of this library, not CSS functions, and round-trip through getCssColor() and getColorObj() like the others.

Models can also be built directly by type:

Nearest named color

getClosestWebColor() measures the Euclidean distance in sRGB, which is not perceptually uniform. getClosestWebColorByDeltaE() measures the CIE76 difference in CIE Lab, which tracks perceived difference.

PDF and spot colors

Eight of the eleven default spot color names are also CSS color names (red, green, blue, cyan, magenta, yellow, black, white) and resolve to the spot color. They agree with their CSS namesake except green: the spot Green is #00ff00 while CSS green is #008000. Pass $allowSpot = false to getPdfColor(), getPdfFillColor(), getPdfStrokeColor(), getColorObject(), getPdfRgbComponents() or getPdfCmykComponents() to force the device color.

The remaining three, key, all and none, are spot-only names. With $allowSpot = false they do not resolve: getPdfColor() and the component accessors return an empty string and getColorObject() returns null.

Every registered spot color must be emitted by getPdfSpotObjects() before getPdfSpotResources() is called; otherwise the resource writers raise a Com\Tecnick\Color\Exception.

Exceptions

Com\Tecnick\Color\Exception (a \Exception) signals an invalid input. Com\Tecnick\Color\UnknownComponentException (a \LogicException) signals a component name a model does not define, and is not swallowed by the lenient accessors tryGetColorObj() and getColorObject(). Both implement Com\Tecnick\Color\ExceptionInterface, so a single catch covers them.

See example/index.php for a web-color conversion table covering RGB, HSL, the Acrobat JavaScript form and the nearest-color inversion.

Roles and extension points

Pdf extends Spot extends Web extends Css, so one object offers the parser, the spot registry and the PDF writer. Each role also has its own interface to type against: ColorParserInterface, SpotRegistryInterface and PdfColorWriterInterface.

Four methods can be overridden: Web::getColorObj(), Spot::getSpotColor(), Pdf::getPdfColor() and Pdf::getColorObject(), plus the protected parser methods on Css and Spot::resolveSpotColorData(). Every other public method is final. A subclass that overrides one of the four must mirror its signature exactly.


Versioning

This project follows Semantic Versioning. A change that alters a public signature, the bytes a method emits, or whether an input parses, goes in a major release. See CHANGELOG.md.


Development

make server serves the example/ directory on http://localhost:8000. Use a custom port with make server PORT=8080.


Packaging

For system packages, bootstrap with:


Contributing

Contributions are welcome. Please review CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.


All versions of tc-lib-color with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-pcre Version *
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 tecnickcom/tc-lib-color contains the following files

Loading the files please wait ...