PHP Imagecolorallocatealpha () function

PHP

Syntax:
int imagecolorallocatealpha ($image, $red, $green, $blue, $alpha)
Parameters:This function takes five parameters as above and described below:
  • $image:is returned by one of the image creation functions, such as imagecreatetruecolor(). Used to create the size of the image.
  • $red:This parameter is used to set the red component value.
  • $green:this parameter is used to set the value of the component to green.
  • $blue:this parameter is used to set the value of the component to blue.
  • $alpha:this parameter is used to set the transparency of the image. The $alpha value ranges from 0 to 127, where 0 is fully opaque and 127 is fully transparent.
Return Value:This function returns an identifier colors if successful, or FALSE if color distribution failed.Exception:5.1.3 or later returns false if distribution failed, otherwise -1 earlier.The following programs illustrate the imagecolorallocatealpha() functionin PHP:Program 1:  
// Create the size of the image or blank image. $image = imagecreatetruecolor (500, 300) ;  
// Set the background color of the image. $bg = imagecolorallocate ( $image , 0, 103, 0);  
// Fill the background with the selected color above. imagefill ( $image , 0, 0, $bg );  
// assign 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);  
// Draw a filled circle imagefilledellipse ( $image , 200, 100, 150, 150, $yellow ); imagefilledellipse ( $image , 275, 100, 150, 150, $red ); imagefilledellipse ( $image , 240, 180, 150, 150, $blue );  
// display the correct title! header ( `Content-Type: image / png` );  
// display the result imagepng ( $image ); imagedestroy ( $image ); ?>
Output: Program 2:  
// Create the size of the image or blank image. $image = imagecreatetruecolor (500, 300);  
// Set the background color of the image. $bg = imagecolorallocate ( $image , 0, 103, 0);  
// Fill the background with the selected color above. imagefill ( $image , 0, 0, $bg );  
// assign colors with alpha values ​​ $yellow = imagecolorallocatealpha ( $image , 255, 255, 0, 75); $blue  = imagecolorallocatealpha ( $image , 0, 0, 255, 75);  
// Draw a filled circle imagefilledellipse ( $image , 200, 150, 150, 150, $yellow ); imagefilledellipse ( $image , 280, 150, 150, 150, $blue );  
// display the correct title! header ( `Content-Type: image / png` );  
// display the result imagepng ( $image ); imagedestroy ( $image ); ?>
Output: Related Articles:
  • PHP | Imagepolygon() Function
  • PHP | Imagechar() Function
  • PHP | Imageellipse() function
Link: http://php.net/manual/en/function.imagecolorallocatealpha.php



Get Solution for free from DataCamp guru