Create a darker shade of a hex color:
function hexDarker($hex,$factor = 30)
{
$new_hex = '';
$base['R'] = hexdec($hex{0}.$hex{1});
$base['G'] = hexdec($hex{2}.$hex{3});
$base['B'] = hexdec($hex{4}.$hex{5});
foreach ($base as $k => $v)
{
$amount = $v / 100;
$amount = round($amount * $factor);
$new_decimal = $v - $amount;
$new_hex_component = dechex($new_decimal);
if(strlen($new_hex_component) < 2)
{ $new_hex_component = "0".$new_hex_component; }
$new_hex .= $new_hex_component;
}
return $new_hex;
}
Example, making a new colour 50% darker than the first:
<?
$myCol = "FFCC99";
$newCol = hexDarker($myCol, 50);
?>
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP , PHP , HTML , PDF , Excel Colors - Make a hex color lighter Categories : PHP , Colors function_exists -- Return true if the given function has been defined Categories : PHP , PHP Functions , Functions javascript cookie settings Categories : PHP , C++ , AJAX Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar , Date Time , PHP Class to Create protected URLs Categories : PHP , PHP Classes , URLs Is there any way to test that the $result has null values or not without reading the field values in the results in postgre?
Categories : PostgreSQL , PHP , Databases Tag content retrieval from websites with preg_match Categories : PHP , Regexps , Arrays , HTML and PHP Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI Categories : Variables , PHP Options and Info , Arrays , URLs , PHP Classic guest book made with PHP and Flash Categories : PHP , Flash , Java Script getting the name of the current script and query string Categories : PHP , Global Variables , Variables , URLs How to get the exit code of a function ran by system(). Categories : PHP Zephyr: AJAX Based Framework for PHP5 Developers Categories : PHP , AJAX , Frameworks , Java Script , Web Applications GetImageSize -- Get the size of a GIF, JPEG, PNG or SWF image Categories : PHP , PHP Functions , Graphics Convert text to 'quoted printable' without the IMAP package installed. Categories : PHP , Mail , IMAP
matthew waygood wrote : 959
Hex colour values are not always 6 digits, they are sometimes 3, but this wasn`t checked for. Other than this a good example. (#fff = #0f0f0f)