PHP | imagealphablending() Function
Last Updated :
23 Aug, 2019
The imagealphablending() function is an inbuilt function in PHP which is used to set the blending mode for an image. This function allows to two different modes (blending mode and non-blending mode) to drawing truecolor images. Blending mode is not available when drawing used palette images.
Syntax:
bool imagealphablending( $image, $blendmode )
Parameters: This function accepts two 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.
- $blendmode: This parameter is used to check the blending mode is enable or not. The default value is True for true color image and False otherwise.
Return Value: This function returns True on success or False on failure.
Below programs illustrate the imagealphablending() function in PHP:
Program 1:
<?php
$image = imagecreatetruecolor(300, 500);
imagealphablending( $image , true);
$background_color = imagecolorallocate( $image , 255, 255, 255);
imagefill( $image , 0, 0, $background_color );
imagefilledrectangle( $image , 50, 50, 450, 250, imagecolorallocate( $image , 0, 255, 0));
header( 'Content-Type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>
|
Output:
Program 2:
<?php
$image = imagecreatefrompng(
imagealphablending( $image , true);
$green = imagecolorallocate( $image , 0, 255, 0);
imagerectangle( $image , 5, 10, 660, 100, $green );
header( 'Content-Type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>
|
Output:
Reference: http://php.net/manual/en/function.imagealphablending.php
Share your thoughts in the comments
Please Login to comment...