PHP | imagecolorallocate() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The imagecolorallocate() function is an inbuilt function in PHP which is used to set the color in an image. This function returns a color which is given in RGB format. Syntax: int imagecolorallocate ( $image, $red, $green, $blue ) Parameters: This function accepts four 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. Return Value: This function returns a color identifier on success or FALSE if the color allocation failed. Below programs illustrate the imagecolorallocate() function in PHP. Program 1: php <?php // It create the size of image or blank image. $image_size = imagecreatetruecolor(500, 300); // Set the background color of image using // imagecolorallocate() function. $bg = imagecolorallocate($image_size, 0, 103, 0); // Fill background with above selected color. imagefill($image_size, 0, 0, $bg); // output image in the browser header("Content-type: image/png"); imagepng($image_size); // free memory imagedestroy($image_size); ?> Output: Program 2: php <?php // It create the size of image or blank image. $image_size = imagecreatetruecolor(500, 300); // Set the background color of image. $bg = imagecolorallocate($image_size, 0, 103, 0); // Fill background with above selected color. imagefill($image_size, 0, 0, $bg); // Set the colors of image $white_color = imagecolorallocate($image_size, 255, 255, 255); // Draw a circle imagearc($image_size, 200, 150, 200, 200, 0, 360, $white_color); // output image in the browser header("Content-type: image/png"); imagepng($image_size); // free memory imagedestroy($image_size); ?> Output: Related Articles: PHP | imageellipse() Function PHP | imagearc() Function PHP | imagefilledellipse() Function Reference: https://www.php.net/manual/en/function.imagecolorallocate.php Comment V vijay_raj Follow 0 Improve V vijay_raj Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-function Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like