The imagecolorallocatealpha() function is an inbuilt function in PHP which is used to allocate the color for an image. This function is same as imagecolorallocate() function with addition of transparency parameter $alpha. This function accepts five parameters and returns color identifier on true or false on failure.
Syntax:
php
Output:
Program 2:
php
Output:
Related Articles:
Reference: https://www.php.net/manual/en/function.imagecolorallocatealpha.php
int imagecolorallocatealpha ( $image, $red, $green, $blue, $alpha )Parameters: This function accepts five parameters as mentioned above and described below:
- $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
- $red: This parameter is used to set value of red color component.
- $green: This parameter is used to set value of green color component.
- $blue: This parameter is used to set value of blue color component.
- $alpha: This parameter is used to set the transparency of image. The value of $alpha lies between 0 to 127 where 0 represents completely opaque while 127 represents completely transparent.
<?php
// It create the size of image or blank image.
$image = imagecreatetruecolor(500, 300);
// Set the background color of image.
$bg = imagecolorallocate($image, 0, 103, 0);
// Fill background with above selected color.
imagefill($image, 0, 0, $bg);
// allocate colors with alpha values
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$red = imagecolorallocatealpha($image, 255, 0, 0, 75);
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
// Drawing filled circle
imagefilledellipse($image, 200, 100, 150, 150, $yellow);
imagefilledellipse($image, 275, 100, 150, 150, $red);
imagefilledellipse($image, 240, 180, 150, 150, $blue);
//output a correct header!
header('Content-Type: image/png');
//output the result
imagepng($image);
imagedestroy($image);
?>
Program 2:
<?php
// It create the size of image or blank image.
$image = imagecreatetruecolor(500, 300);
// Set the background color of image.
$bg = imagecolorallocate($image, 0, 103, 0);
// Fill background with above selected color.
imagefill($image, 0, 0, $bg);
// allocate colors with alpha values
$yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
$blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
// Drawing filled circle
imagefilledellipse($image, 200, 150, 150, 150, $yellow);
imagefilledellipse($image, 280, 150, 150, 150, $blue);
//output a correct header!
header('Content-Type: image/png');
//output the result
imagepng($image);
imagedestroy($image);
?>
Related Articles:
Reference: https://www.php.net/manual/en/function.imagecolorallocatealpha.php