Download the PHP package ssnepenthe/color-utils without Composer

On this page you can find all versions of the php package ssnepenthe/color-utils. 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?

All versions of color-utils with dependencies

Informations about the package color-utils

color-utils

This package is intended to provide a variety of SASS-like color manipulation functions.

Requirements

Composer, PHP 7.0 or later.

Installation

Install using Composer:

Usage

All functions listed are within the SSNepenthe\ColorUtils namespace.

Color Representation

Create Color objects using the color function:

color(array $color)

$color is an array of $channel => $value pairs. Valid channels are red, green, blue, hue, saturation, lightness and alpha.

color(string $color)

$color is a string representation of a color in one of the following formats:

color(int $red, int $green, int $blue, [float $alpha])

0 - 255 range for each of $red, $green and $blue, 0 - 1 for $alpha.

color(float $hue, float $saturation, float $lightness, [float $alpha])

0 - 360 range for $hue, 0 - 100 for each of $saturation and $lightness, 0 - 1 for $alpha.

Regarding the previous two examples:

The values 255, 0 and 51 could technically represent RGB values as well as HSL values. In cases like this, RGB takes precedence over HSL.

If you need finer control, use the following functions:

hsl(float $hue, float $saturation, float $lightness)

hsla(float $hue, float $saturation, float $lightness, float $alpha)

rgb(int $red, int $green, int $blue)

rgba(int $red, int $green, int $blue, float $alpha)

Lastly, the hsla and rgba functions can also be used to adjust the transparency of an existing color:

Color Components

Individual color components are accessible using the following functions (which each accept any $color argument recognized by the color function, including a complete color object):

alpha($color)

Get the alpha channel of a color.

blue($color)

Get the blue channel of a color.

brightness($color)

Calculates color brightness on a scale from 0 (black) to 255 (white).

green($color)

Get the green channel of a color.

hue($color)

Get the hue channel of a color.

is_bright($color)

Accepts an optional $threshold float as the last parameter with a default of 127.5. Checks brightness($color) >= $threshold.

is_light($color)

Accepts an optional $threshold float as the last parameter with a default of 50.0. Checks lightness($color) >= $threshold.

lightness($color)

Get the lightness channel of a color.

looks_bright($color)

Accepts an optional $threshold float as the last parameter with a default of 127.5. Checks perceived_brightness($color) >= $threshold.

name($color)

Get the name (keyword) representation of a color. Returns an empty string if none is found.

opacity($color)

Alias of alpha($color).

perceived_brightness($color)

Calculates the perceived brightness of a color on a scale from 0 (black) to 255 (white).

red($color)

Get the red channel of a color.

relative_luminance($color)

Calculates the relative luminance of a color on a scale from 0 (black) to 1 (white).

saturation($color)

Get the saturation channel of a color.

Color Calculations

The following functions calculate differences between two given colors:

brightness_difference(Color $color1, Color $color2)

Calculates brightness difference on a scale from 0 to 255.

color_difference(Color $color1, Color $color2)

Calculates color difference on a scale from 0 to 765.

constrast_ratio(Color $color1, Color $color2)

Calculates the contrast ratio between two colors on a scale from 1 to 21.

Color Transformations

Colors can be transformed using the following functions (all accept any $color argument recognized by the color function):

adjust_color($color, array $channels)

Creates a new color by increasing/decreasing one or more channel values of $color. This can change red, green, blue, hue, saturation, lightness and alpha channels. $channels are specified as an array of $channel => $amount pairs.

change_color($color, array $channels)

Creates a new color by changing one or more channel values of $color. This can change red, green, blue, hue, saturation, lightness and alpha channels. $channels are specified as an array of $channel => $amount pairs.

invert($color)

Creates a new color by inverting (subtracting from 255) the red, green and blue channels of $color. Alpha is left unchanged.

mix(Color $color1, Color $color2, int $weight = 50)

Creates a new color by averaging the red, green and blue channels from $color1 and $color2, with $color1 optionally weighted by $weight%. Alpha is also considered. Uses the same algorithm as SASS.

scale_color($color, array $channels)

Creates a new color by scaling one or more channel values of $color. This can change red, green, blue, hue, saturation, lightness and alpha channels. $channels are specified as an array of $channel => $percent pairs, and each channel value is scaled by $percent% of the max possible adjustment.

In the example below, green is 100 and we want to scale positively by 50%. The maximum allowed value is 255 which means the maximum possible adjustment is 155. The new green value then becomes 100 + (155 * 0.5).

Likewise, blue is 150 and we want to scale negatively by 50%. The minimum allowed value is 0 which means the maximum possible adjustment is -150. The new blue value then becomes 150 + (-150 * 0.5).

adjust_hue($color, float $degrees)

Alias of adjust_color($color, ['hue' => $degrees]).

complement($color)

Alias of adjust_color($color, ['hue' => 180]).

darken($color, float $amount)

Alias of adjust_color($color, ['lightness' => -1 * $amount]).

desaturate($color, float $amount)

Alias of adjust_color($color, ['saturation' => -1 * $amount]).

fade_in($color, float $amount)

Alias of opacify($color, $amount).

fade_out($color, float $amount)

Alias of transparentize($color, $amount).

grayscale($color)

Alias of change_color($color, ['saturation' => 0]).

lighten($color, float $amount)

Alias of adjust_color($color, ['lightness' => $amount]).

opacify($color, float $amount)

Alias of adjust_color($color, ['alpha' => $amount]).

saturate($color, float $amount)

Alias of adjust_color($color, ['saturation' => $amount]).

shade($color, int $weight = 50)

Alias of mix(color('black'), color($color), $weight).

tint($color, int $weight = 50)

Alias of mix(color('white'), color($color), $weight).

transparentize($color, float $amount)

Alias of adjust_color($color, ['alpha' => -1 * $amount]).


Version
Requires php Version >=7.0

The package ssnepenthe/color-utils contains the following files

Loading the files please wait ....