Easy Tutorial
❮ Func Mysqli Get Charset Func Ftp Put ❯

PHP imagecolorallocate - Allocate a Color for an Image

PHP Image Processing

imagecolorallocate — Allocate a color for an image.

Syntax

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

imagecolorallocate() returns a color identifier representing the color composed of the given RGB components. red, green, and blue are the intensities of the red, green, and blue components of the color. These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. imagecolorallocate() must be called to create each color that is to be used in the image represented by image.

Returns -1 if the allocation failed.

Note: The first call to imagecolorallocate() fills the background color in palette-based images, i.e., images created using imagecreate().

Example

<?php
header("Content-type: image/png");
$im = @imagecreate(100, 50)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

The above example will output an image as shown below:

Related Articles

PHP Image Processing

❮ Func Mysqli Get Charset Func Ftp Put ❯