Create gradient color from PHP

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

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

Please help me

+3
css php
Aug 18 '10 at 10:29
source share
2 answers

Links to Michael Michael are pretty scary. But the solution is simple. This might be clearer if you are looking at just a grayscale 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 use a 3D vector (RGB) instead of a 1D vector.

FROM.

+5
Aug 18 '10 at 11:20
source share

The answer to this question is your solution, only in Javascript ...

Create a lighter / darker color in css using javascript

I'm not going to write this, but a simple google search for "lighten hex color php" gives:

 function colourBrightness($hex, $percent) { // Work out if hash given $hash = ''; if (stristr($hex,'#')) { $hex = str_replace('#','',$hex); $hash = '#'; } /// HEX TO RGB $rgb = array(hexdec(substr($hex,0,2)), hexdec(substr($hex,2,2)), hexdec(substr($hex,4,2))); //// CALCULATE for ($i=0; $i<3; $i++) { // See if brighter or darker if ($percent > 0) { // Lighter $rgb[$i] = round($rgb[$i] * $percent) + round(255 * (1-$percent)); } else { // Darker $positivePercent = $percent - ($percent*2); $rgb[$i] = round($rgb[$i] * $positivePercent) + round(0 * (1-$positivePercent)); } // In case rounding up causes us to go to 256 if ($rgb[$i] > 255) { $rgb[$i] = 255; } } //// RBG to Hex $hex = ''; for($i=0; $i < 3; $i++) { // Convert the decimal digit to hex $hexDigit = dechex($rgb[$i]); // Add a leading zero if necessary if(strlen($hexDigit) == 1) { $hexDigit = "0" . $hexDigit; } // Append to the hex string $hex .= $hexDigit; } return $hash.$hex; } 

http://lab.pxwebdesign.com.au/?p=14

Your Google is as good as mine!

+2
Aug 18 '10 at 10:41
source share



All Articles