note 48375 deleted from function.hexdec by tularis

From: Date: Tue, 21 Dec 2004 10:50:57 +0000
Subject: note 48375 deleted from function.hexdec by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82122@lists.php.net to get a copy of this message
Note Submitter: php at arzynik dot com ---- A function to change the tint to the color you specify by wichever ammount you specify. <?php $color = "#09112A"; $tint_red = 125; $tint_green = 100; $tint_blue = -100; colortint($color,$tint_red,$tint_green,$tint_blue); function colortint($c,$tr,$tg,$tb) { if (eregi("#",$c)) { $c = str_replace('#','',$c); $p = 1; } $r = hexdec(substr($c,0,2))+$tr; $g = hexdec(substr($c,2,2))+$tg; $b = hexdec(substr($c,4,2))+$tb; if ($r > 255) $r = 255; elseif ($r < 0) $r = 0; if ($g > 255) $g = 255; elseif ($g < 0) $g = 0; if ($b > 255) $b = 255; elseif ($b < 0) $b = 0; $r = dechex($r); $g = dechex($g); $b = dechex($b); if (strlen($r) == 1) $r = "0".$r; if (strlen($g) == 1) $g = "0".$g; if (strlen($b) == 1) $b = "0".$b; $c = $r.$g.$b; if ($p == 1) $c = "#".$c; return $c; } ?> ---- Reason: bad code

« previous php.notes (#82122) next »