Download the PHP package ryangjchandler/color without Composer

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

A simple Color object for PHP packages and applications. 🎨

Installation

This package can be installed via Composer:

Usage

This package provides a single RyanChandler\Color\Color object.

Creating a color

To create a color, instantiate a new RyanChandler\Color\Color object:

The constructor accepts three optional arguments. The red, green and blue decimal representations of your color.

If you prefer using static constructors you can use the Color::new() method, à la Rust.

Creating a color from a hex

If you wish to create a color using the hex representation, you can use the Color::hex() method.

This will convert your hex representation into the RGB equivalent.

The # is not compulsory. It will only be removed if the string provided starts with it.

It's worth noting that any alpha values specified on the hex value will be stripped since the string is clamped to a length of 6. This is something that might be supported in a future version.

Creating a color from HSL values

You can also use hue, saturation and lightness values to create a color using the Color::hsl() method.

This will convert your HSL values into the RGB equivalent.

You can also define the alpha as an optional fourth argument Color::hsl(0, 0, 100, 0.5)

Generating a random color

You can generate a random color using the Color::random() method.

Accessing the red, green and blue values

Each color value can be accessed using a public property on the Color object.

Getting the hex representation

If you wish to get the hex equivalent of your color, you can use the Color::toHex() method.

Getting the HSL representation

If you wish to get the HSL equivalent of your color as an array, you can use the Color::toHsl() method.

Getting the string representation

By default, the Color::toString() method returns a tuple-like string.

You can also use the Color::toString() method to retrieve the hex representation.

Or use PHP's typecasting to get a string instead.

Getting an array

You can use the Color::toArray() method to get all three color values in an ordered list.

The array does not use string-keys, so you can unpack the array into separate variables too.

Finding the distance between 2 colors

If you need to calculate the distance between 2 colors, you can use the Color::distanceBetween() method.

The return value is the distance between the 2 colors, squared. Generally speaking, this number will be more readable and recognisable than the radical (result of the square root).

Using an existing Color

If you already have a Color object, you can use the Color::distanceTo() method as well.

It is worth noting that the distance calculations and Color objects do not support alpha-based colors. This is potentially something that will be added in the future.

Comparing colors

You can compare two colors using the Color::bothEqual() method.

You can also compare one color to another using the equals method on one of the colors.


All versions of color with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
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 ryangjchandler/color contains the following files

Loading the files please wait ....