Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate gradient color from PHP

Tags:

css

php

I want to know how to build a function that give the code of an color and display a gradient of this color. For example:

function generate_color(int colorindex)
{  .......
   .......
   Generate 10  pale colors of this color.


}

Please help me

like image 649
eni Avatar asked Dec 13 '25 07:12

eni


1 Answers

The code Michael references is rather scary. But the solution is straightforward. It may be clearer if you consider simply a grey scale image:

 function create_pallette($start, $end, $entries=10)
 {
    $inc=($start - $end)/($entries-1);
    $out=array(0=>$start);
    for ($x=1; $x<$entries;$x++) {
      $out[$x]=$start+$inc * $x;
    }
    return $out;
 }

Only using a 3D vector (RGB) instead of a 1D vector.

C.

like image 73
symcbean Avatar answered Dec 14 '25 23:12

symcbean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!