RGBA


PHP Old Method:

<?php
$image = imagecreatetruecolor(1, 1);
$r = (int)$_GET['r'];
$g = (int)$_GET['g'];
$b = (int)$_GET['b'];
$a = (float)$_GET['a'];
$white = imagecolorallocate($image, 255, 255, 255);
$color = imagecolorallocatealpha($image, $r, $g, $b, 127*(1-$a));
imagefill($image, 0, 0, $white);
imagefilledrectangle($image, 0, 0, 1, 1, $color);
 
header('Content-type: image/png');
imagepng($image);
?>

Now just apply that to a div…

<style type="text/css">
.box {
background: url(rgba.php?r=239&g=182&b=29&a=.25);
}
</style>
 
<div class="box">
    <!--CONTENT-->
</div>

CSS3 Method:

<style type="text/css">
.box {
background: rgba(239, 182, 29, .25);
}
</style>
 
<div class="box">
    <!--CONTENT-->
</div>

No comments:

Post a Comment