A simple PHP library for converting colors and create color gradients.
This release allows to convert colors between RGB an HSV color modes. It also allows to create color gradients between two given colors and a number of steps between them.
You can view some sample code in the test folder, but basically there are two functions.
// New red color
$newColor = new RGB(255, 0, 0);
// Convert to HSV mode
$newHSV = $newColor->convertToHSV();
// Returns a HSV object with values Hue = 0.0, Saturation 1.0, Value = 1.0You also can get the hexadecimal code for easy printing in a web page.
$newColor = new RGB(100, 200, 150);
$hexString = $newColor->getHexaColorString();
// Returns a beautiful green #64c896Getting gradients is very easy too. Simply create 2 color objects, no matter wich mode.
Create a new Gradient object and pass the colors and the steps you want to create between colors. More steps creates a more gentle gradient.
The object will contain an array with the given length. Each position will be a HSV color.
// First Color: green
$first = new RGB(0, 255, 0);
// Second Color: red
$second = new RGB(255, 0, 0);
// Create the gradient. If steps is not set, default value is 10.
$gradient = new Gradient($first, $second, 12);
// Loop the array
foreach ($gradient->getGradientArr() as $color) {
// Get the color with $color->getHexaColorString();
}It will return a 12 position array with these colors:
Here is a sample of diferent level gradients:
