Skip to content

Instantly share code, notes, and snippets.

@anthonyshort
Created February 19, 2010 02:04
Show Gist options
  • Save anthonyshort/308321 to your computer and use it in GitHub Desktop.
Save anthonyshort/308321 to your computer and use it in GitHub Desktop.
function Scaffold_hexa2rgba($hex,$alpha=1)
{
$hex = str_replace('#','',$hex);
$r = $g = $b = 0;
switch(strlen($hex)){
case 3:
list($r,$g,$b) = str_split($hex);
$r = hexdec($r.$r);
$g = hexdec($g.$g);
$b = hexdec($b.$b);
return "rgba($r,$g,$b,$alpha)";
break;
case 6:
list($r1,$r2,$g1,$g2,$b1,$b2) = str_split($hex);
$r = hexdec($r1.$r2);
$g = hexdec($g1.$g2);
$b = hexdec($b1.$b2);
return "rgba($r,$g,$b,$alpha)";
break;
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment