Download the PHP package webzille/colorutility without Composer
On this page you can find all versions of the php package webzille/colorutility. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package colorutility
Webzille Color Utility
The Webzille Color Utility is a comprehensive PHP package designed for advanced color manipulation across multiple color models, including CylindricalLAB, HEX, HSL, HSLA, HSV, LAB, RGB, RGBA and RYB. This powerful utility allows developers to perform various operations on colors, such as conversions, calculations, and transformations, using an intuitive and flexible API.
Features
- Multiple Color Models: Work with a variety of color models to meet the needs of different graphic and application requirements.
- Color Manipulation: Easily manipulate color properties, including adjustments, blending, and transformations.
- Color Comparisons: Compare colors to find differences, distances, and similarities, both visually and through calculated metrics.
- Advanced Calculations: Calculate angles, distances, and deviance to understand color relationships better.
- Color Harmonies: Generate color schemes based on harmonic rules like complementary, analogous, triadic, and more.
- Random Color Generation: Generate a random color in RGB color model with the option to use seeds to come back to original color.
Installation
To use the Webzille Color Utility in your project, include it via Composer:
Color Space / Wheel
This package includes the following color spaces / wheels to be used in scheme creation.
- RYB Traditional Painter: This color wheel is based on the traditional painter’s perspective, where the primary colors are red, yellow, and blue. It's used extensively in art and design education, emphasizing how painters mix colors to achieve a broad spectrum. This model is ideal for applications that require a naturalistic approach to color mixing and harmony, as it aligns with traditional artistic techniques.
- HSV (Hue, Saturation, Value): HSV represents colors in terms of their hue, saturation, and value (brightness). Hue is the color type, saturation represents the intensity of the color, and value indicates the brightness. This model is particularly useful for applications needing intuitive color adjustments since it separates color-making components in a way that aligns with human perception of color.
- LAB: LAB color space includes three components - L for lightness, A and B for color spectrums from green to red and blue to yellow, respectively. It is designed to approximate human vision and is not dependent on how colors are created with light or pigments. This model is useful for achieving precise color manipulation and ensuring color consistency across different devices and viewing conditions.
Usage
Basic Usage
After including the package, you can start by creating color objects in any supported color space.
Setting color from string factory
You may set a color object from string from any of the websafe color formats (RGBA, RGB, HSLA, HSL, HEX and named colors) using the SetColor::fromString(string $string)
factory.
Going between color spaces / wheels
By default the package uses the RYB Traditional Painter color wheel for creating color schemes or for any of the color manipulating methods available. It is easy though to change the color wheel from RYB to either HSV or to LAB by passing the class string name to setSpace()
method.
You could also simply convert the color object from RGB to one of the color spaces like RYB::class
, LAB::class
or HSV::class
instead of specifying for a specific color space.
Which is the same as
If the color model you are working with has it's own methods for findColorByAngle()
and the like, it will use it's own such methods instead of what $this->colorSpace
is set to. For instance:
In the above example, even though I set the color space to be used to be in RYB::class
, since LAB color model has that method of it's own it will use it, resulting in it using it's own color space. To manipulate colors in LAB while utilizing RYB color space, you would need to explicitly convert between the methods
Catching colors from string
You can catch color from strings for whatever parsing you need. This method also catches most popular named colors.
If you set $transparency
to false, than it would ignore the 'transparent' colors.
Viewing color
The color class provides a way to view a sample of the color that the object holds. The method accepts an optional string parameter that allows you to add a label to the color sample to help keep track of each color object.
The method detects if the object is in a websafe color format and converts to RGB in case the color object is not in a websafe color format (like LAB or RYB).
Manipulating Colors
Adjust color properties, blend colors, or calculate color harmonies.
Blending colors are done only within RYB color space at the moment. You may convert the color objects to RYB, blend them and then convert the resulting color back to your own color model you using. The weight is a number between 0 and 1 that determines how the colors blend. If weight is 0, the blend will show only the first color. If weight is 1, it will show only the second color. The closer the weight is to 1, the more the blend will favor the second color. This method smooths out the transition between colors, making the blend gradual and more natural-looking.
All colors can be brighter then they are, even fully saturated yellow (rgb(255, 255, 0)
). You could adjust the shade of the color (lighten it or darken it) using a percentage relative to the current brightness/shade of the color.
Analyzing Colors
Calculate angles, distances, and perform advanced analysis like checking if the color is light or dark.
Generating Color Schemes
Generate color schemes based on predefined harmonies.
Random Color Generation
You can generate a random color with or without a seed. The random color factory returns an array with the first element being the color object and the second being the seed used to generate that color object.
The random color factory accepts the optional $seed parameter if you want to create the color object generated before.
theme.php provides an example using the random color factory utilizing various other features of this package.
Color Conversions
The Webzille Color Utility provides extensive support for converting between various color models, allowing seamless transitions across different color formats. This feature is crucial for applications that need to work with multiple color specifications or require specific color manipulations that are easier in certain models.
Converting Colors
Convert colors between different models to fit the context of your application.
If you ever need to use a different color space which would require you to convert a color from one color model to another and than need the color model converted back to what it was before you converted it, you could chain the backTo()
method to the end of the method chains.
That is good if the color object would be dynamically set and the result needs to be the same as what it was before any conversions took place. Otherwise you could simply chain the proper conversion method to get back to the original color model.
Conversion Examples
Here’s how you can convert between different color formats using the Webzille Color Utility:
Every color format has a method to convert to any of the other available formats.
Credit
The original authoer for the conversion methods between RYB and RGB methods is Arah J. Leonard used under the MIT license. Source code that was ported to JavaScript that I ported to PHP. I don't know where the original code is but that is what I found and used that works here.
Contributing
Contributions to the Webzille Color Utility are welcome! Please ensure that you submit pull requests to the development branch.
License
This project is licensed under the MIT License - see the LICENSE file for details.