[ create a new paste ] login | about

Link: http://codepad.org/MTGLWVd0    [ raw code | output | fork ]

PHP, pasted on Feb 5:
<?php

function darken_color($rgb, $darker=2) {

	$hash = (strpos($rgb, '#') !== false) ? '#' : '';
	$rgb = (strlen($rgb) == 7) ? str_replace('#', '', $rgb) : ((strlen($rgb) == 6) ? $rgb : false);
	if(strlen($rgb) != 6) return $hash.'000000';
	$darker = ($darker > 1) ? $darker : 1;

	list($R16,$G16,$B16) = str_split($rgb,2);

	$R = sprintf("%02X", floor(hexdec($R16)/$darker));
	$G = sprintf("%02X", floor(hexdec($G16)/$darker));
	$B = sprintf("%02X", floor(hexdec($B16)/$darker));

	return $hash.$R.$G.$B;
}

$color = '#45ff33';
$darker = darken_color($color);

echo "$color => $darker";

?>


Output:
1
#45ff33 => #227F19


Create a new paste based on this one


Comments: