Download the PHP package savvywombat/color without Composer

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

SavvyWombat Color

Latest Version on Packagist Supported PHP Version Build Code Coverage

A PHP package to help convert between and manipulate HSL and RGB colorspaces/types.

Main features:

Installation

Usage

Creating a color

The following patterns are available by default to create a color:

Converting a color

Colors can be converted to any other registered color type:

Modifying a color

The following methods are available on any registered color type by default:

All methods return a modified copy of the original object, leaving the original unmodified, and will accept the following argument formats:

Red, green, blue values are clamped in the range of 0..255. This means that adding 100 to a color which already has a red value of 200 will return a color with red set to 255.

Similarly, saturation and lightness are clamped in the range 0..100, while alpha is clamped between 0 and 1.

Hue is not clamped, as it is possible to rotate more than 360 in either direction (and 420° is equivalent to 60°). Because of this, the fractional pattern ('+1/2') should not be used as there is no minimum or maximum.

Extending

Custom color types

The package allows you to create your own color types. These must extend Color, and implement the following methods from the ColorInterface:

Registering color types

You will need to register the class to allow conversion to and from your new color:

You can replace existing color types with new ones.

You can get a list of registered color types via Color::registeredColors().

public static function fromString(string $colorSpec): ColorInterface

The fromString accepts a color specification and tests it against the registered patterns and extracts the information.

Registering color specification patterns

To register a color specification pattern you must first register the color type it will apply to:

You register new specifications for any registered color type, including the default types. You can also override registered patterns so that they apply to different color types.

You can get a list of registered color specification via Color::registeredColorSpecs().

public function __toString(): string;

public static function fromRGB(Rgb $rgb): ColorInterface

This method is used to allow conversion from one color type to any another that has been registered. This means that you only have to specify how to convert to your new type from an RGB color.

public function toRGB(): Rgb

The abstract \SavvyWombat\Color\Color already implements this method:

The red, green, blue and alpha properties are also defined on the abstract. You can either reimplement the method, or set these values in your color type constructor to make use of the default implementation:

It is recommended that you use the default implementation, as the red, green and blue properties are exposed in the public interface.

Custom color modifiers

Color modifiers are methods on color types that are registered and made available to all other color types.

Calling a modifier on a color type will convert it to the type that implements the registered method, and then convert the result back to the original type. To help with this implicit conversion, custom modifiers must return an object which extends Color - ideally, it should be a copy of the same type the method is implemented on.

Color::adjustValue($originalValue, $newValue, $max = 0, $min = 0) handles the various relative arguments (±50 or ±50%) to produce the new calculated value for the property being modified.

The modifier is also responsible for ensuring the new value is valid for the property being modified.

Support for color keywords

and will accept any of the CSS color keywords to create a Hex color.

If you wish to generate a color of a different type from a keyword, you can convert from the Hex color after creation:

License

The MIT License (MIT). Please see License File for more information.


All versions of color with dependencies

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

Loading the files please wait ....