Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
imagecolorallocate() function in PHP
The imagecolorallocate() function allocates a color for an image.
Syntax
int imagecolorallocate ( $img, $red, $green, $blue )
Parameters
img: Image resource created with imagecreatetruecolor().
red: Red color component
green: Green color component
blue: Blue color component
Return
The imagecolorallocate() function returns a color in RGB format.
Example
The following is an example:
<?php
$img = imagecreatetruecolor(600, 220);
$bgcolor = imagecolorallocate($img, 20, 50, 120);
imagefill($img, 0, 0, $bgcolor);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>
Output
The following is the output:

Advertisements