YouTip LogoYouTip

Php Imagecolorallocate

PHP imagecolorallocate - Allocate a Color for an Image

PHP Image ProcessingPHP Image Processing

imagecolorallocate β€” Allocate 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. The red, green, and blue parameters are the red, green, and blue components of the desired color, respectively. These parameters are integers between 0 and 255, or hexadecimal values from 0x00 to 0xFF. imagecolorallocate() must be called to create each color used in the image represented by image.

Returns -1 if the allocation fails.

Note: The first call to imagecolorallocate() fills the background color for a palette-based image, i.e., an image created with 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 image output from the above example is shown below:

imagecolorallocate example

Related Articles

PHP Image ProcessingPHP Image Processing

← Highcharts 3D ChartsHighcharts Combinations Scatte β†’