Download the PHP package tomloprod/colority without Composer

On this page you can find all versions of the php package tomloprod/colority. 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 colority

GitHub Workflow Status (master) Total Downloads Latest Version License


🎨 About Colority

Colority is a lightweight PHP library designed to handle color transformations, validations and manipulations with ease.

It allows you to instantiate concrete objects according to the color format (RGB, HSL, Hexadecimal) and convert from one format to another.

Additionally, it lets you check if a background color meets the WCAG 2.0 accessibility standard regarding the color contrast ratio in text and UI.

Furthermore, it includes multiple functions such as the following:

✨ Getting Started

Instantiating Color objects

You can convert value colors (strings or, additionally, depending on the color type, arrays) to specific Color objects.

If you cannot specify the original format of the value color, you can use the parse method. This will detect what type of color it is and instantiate a new object or, if the received string does not match any type of color, it will return NULL:

Contrast ratio (WCAG 2.0 standard)

When you have the Color object, you will be able to use all its methods. Below, we describe two of them related to the contrast ratio.

getBestForegroundColor

Returns a Color object with the most suitable foreground color (using the Luminosity Contrast Ratio algorithm).

You can pass an array with Color objects as a parameter, so it chooses the foreground color with the best contrast ratio. If no parameter is specified, it will default to white or black.

getContrastRatio

Returns the contrast ratio (higher is better contrast, lower is worse) between the color invoking this method and the color passed as a parameter. If no color is passed as a parameter, the contrast ratio against black as foreground will be determined.

AA & AAA WCAG levels

Below we show you how to check if a contrast ratio meets WCAG AA and AAA levels using Tomloprod\Colority\Support\Algorithms\ContrastRatioScore.

Color validation

The concrete Color classes have a static method called getParser() which returns an instance of ValueColorParser.

The parse method returns a string with the value color adapted to work correctly with Colority or throws an InvalidArgumentException when it's not valid.

You can use the specific parser for any type of color:

Color conversion

Colority allows you to convert a Color object to any other Color object of the desired format.

Color utilities

getImageColors

It allows you to obtain the colors detected in an image. As the first argument, the path to the image must be provided.

It has an optional second parameter (default is 5) that specifies the number of colors to be returned.

textToColor

Generate a fixed color based on a string.

πŸ§™ Advise Useful for generating a color associated with, for example, a username, mail address, etc, since a string will always return the same color.

getSimilarColor

Allows you to obtain a random color similar (in the same color palette) to a given color.

Ways of using Colority

You can use Colority either with the aliases colority()

or by directly invoking the static methods of the Colority facade:

You decide how to use it πŸ™‚

🧱 Architecture

Colority is composed of several types of elements. Below are some features of each of these elements.

Colority

Tomloprod\Colority\Support\Facades\Colority is a facade that acts as a simplified interface for using the rest of the Colority elements.

Methods

Color

All concrete color classes extend the abstract class Color. Concrete color classes:

Methods

For the HslColor and RgbColor objects, you also have a method getArrayValueColor that will return the value color in array format:

On the other hand, the HslColor object has an additional method called getValueColorWithMeasureUnits, which returns the value color, but with units of measurement (useful for, for example, using it in a CSS style):

πŸš€ Installation & Requirements

Requires PHP 8.2+

You may use Composer to install Colority into your PHP project:

πŸ§‘β€πŸ€β€πŸ§‘ Contributing

Contributions are welcome, and are accepted via pull requests. Please review these guidelines before submitting any pull requests.


Colority was created by TomΓ‘s LΓ³pez and open-sourced under the MIT license.


All versions of colority with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2.0
ext-mbstring 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 tomloprod/colority contains the following files

Loading the files please wait ....