PHP | imagecolordeallocate() Function
Last Updated :
23 Aug, 2019
The imagecolordeallocate() function is an inbuilt function in PHP which is used to de-allocate a color created by imagecolorallocate() or imagecolorallocatealpha() function for an image.
Syntax:
bool imagecolordeallocate( $image, $color )
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 the size of image.
- $color: This parameter holds the color identifier.
Return Value: This function returns True on success or False on failure.
Below programs illustrate the imagecolordeallocate() function in PHP:
Program 1:
<?php
$image_size = imagecreatetruecolor(500, 300);
$bg = imagecolorallocate( $image_size , 0, 103, 0);
$bg = imagecolordeallocate( $image_size , $bg );
imagefill( $image_size , 0, 0, $bg );
header( "Content-type: image/png" );
imagepng( $image_size );
imagedestroy( $image_size );
?>
|
Output:
Program 2:
<?php
$image_size = imagecreatetruecolor(500, 300);
$bg = imagecolorallocate( $image_size , 0, 103, 0);
$bg = imagecolordeallocate( $image_size , $bg );
imagefill( $image_size , 0, 0, $bg );
$white_color = imagecolorallocate( $image_size , 255, 255, 255);
imagearc( $image_size , 200, 150, 200, 200, 0, 360, $white_color );
header( "Content-type: image/png" );
imagepng( $image_size );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imagecolordeallocate.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...