PHP GD Color Transparency Using Alpha Blending


 

PHP GD Color Transparency Using Alpha Blending

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

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

<?php

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");

imagepng($img);

?>

After running the program you will get the following output

Ads