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.
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.
Return Value: This function returns a color identifier on success or FALSE if the color allocation failed.
Exception: 5.1.3 or later version return false if allocation failed otherwise return -1 previously.
Below programs illustrate the imagecolorallocatealpha() function in PHP:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.