Share on Google+Share on Google+

PHP GD Color Transparency Using Alpha Blending

This example shows how to do Color Transparency Using Alpha Blending in php gd.


define("WIDTH", 300);

define("HEIGHT", 300);

$img = imagecreatetruecolor(WIDTH, HEIGHT);

$black = imagecolorallocate($img, 0, 0, 0);

$yellow = imagecolorallocate($img, 0xFF, 0xFF, 00);

$red = imagecolorallocate($img, 255, 0, 0);

$blue_t = imagecolorallocatealpha($img, 0, 0, 0xFF, 0x40);

imagefill($img, 1, 1, $black);

imageline($img, 0,0, WIDTH-1, HEIGHT-1, $blue_t);

imagefilledrectangle($img, (WIDTH/2)-50, (HEIGHT/2)-50, (WIDTH/2)+50, (HEIGHT/2)+50, $yellow);

imagefilledrectangle($img, (WIDTH/2)-30, (HEIGHT/2)-30, (WIDTH/2)+30, (HEIGHT/2)+30, $red);

imagefilledrectangle($img, 10, 10, WIDTH-11, HEIGHT-11, $blue_t);

header("Content-Type: image/png");



After running the program you will get the following output



Posted on: November 13, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null