|
Generate Gradient Within Hex Range In PHP
A function that generates an array of hex colors that forms a gradient, starting from a hex color and ending with another hex color. The number of gradient steps can also be defined.
|
On Monday, September 29th 2008 at 03:12 AM By Andrew Pociu (View Profile)
    (Rated 5 with 1 votes) |
Contextual Ads
More PHP Resources
Advertisement
function Gradient($HexFrom, $HexTo, $ColorSteps)
{
$StepRGB['r'] = ($FromRGB['r'] - $ToRGB['r']) / ($ColorSteps - 1);
$StepRGB['g'] = ($FromRGB['g'] - $ToRGB['g']) / ($ColorSteps - 1);
$StepRGB['b'] = ($FromRGB['b'] - $ToRGB['b']) / ($ColorSteps - 1);
$GradientColors = array();
for($i = 0; $i <= $ColorSteps; $i++)
{
$RGB['r'] = floor($FromRGB['r'] - ($StepRGB['r'] * $i));
$RGB['g'] = floor($FromRGB['g'] - ($StepRGB['g'] * $i));
$RGB['b'] = floor($FromRGB['b'] - ($StepRGB['b'] * $i));
$HexRGB['r'] = sprintf('%02x', ($RGB['r']));
$HexRGB['g'] = sprintf('%02x', ($RGB['g']));
$HexRGB['b'] = sprintf('%02x', ($RGB['b']));
$GradientColors[] = implode(NULL, $HexRGB);
}
return $GradientColors;
}
$Gradients = Gradient("FF5B5B", "FFCA5B", 32);
foreach($Gradients as $Gradient)
{
echo "<div style=\"background-color: #". $Gradient. "; width: 100px; height: 25px;\"></div>";
}
|
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|
Rate this code snippet
Current Comments
|
Related Source Code
There is no related code.
Related Tutorials
There are no related tutorials.
PHP Job Search
|
|
|