Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP imagecolorallocate - Allocate a Color for an Image

PHP imagecolorallocate - Allocate a Color for an Image

PHP Image ProcessingPHP Image Processing

imagecolorallocate — Allocates a color for an image.

Syntax



int imagecolorallocate ( resource $image , int $red , int $green , int $blue )

imagecolorallocate() returns an identifier representing the color composed of the given RGB components. red, green, and blue are the red, green, and blue components of the desired color, respectively. These parameters are integers from 0 to 255 or hexadecimal from 0x00 to 0xFF. imagecolorallocate() must be called to create each color used in the image represented by image.

Returns -1 if allocation fails.

**Note:** The first call to imagecolorallocate() fills the background color of a palette-based image, i.e., the image created with imagecreate() .

Example





The image of the output result of the example above is as follows:

Related Articles

PHP Image ProcessingPHP Image Processing