Skip to content

carlosdomingom/php_colorlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

php_colorlib

A simple PHP library for converting colors and create color gradients.

#00ff00 #2eff00 #5dff00 #8bff00 #b9ff00 #e8ff00 #ffe800 #ffb900 #ff8b00 #ff5d00 #ff2e00 #ff0000

Current version

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.

How it works

You can view some sample code in the test folder, but basically there are two functions.

Converting colors

// 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.0

You 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 #64c896

#64c896 Beautiful green #64c896

Getting gradients

Getting 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:

#00ff00 #2eff00 #5dff00 #8bff00 #b9ff00 #e8ff00 #ffe800 #ffb900 #ff8b00 #ff5d00 #ff2e00 #ff0000

Here is a sample of diferent level gradients:

Gradient sample

About

PHP library for converting color modes and create color gradients

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages