English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Online Tools

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

Object function

PHP Image Processing

PHP imagecolorallocate() function allocation color usage and example

imagecolorallocate — Allocate color for an image.

Syntax

int imagecolorallocate ( resource $image , int $red , int $green , int $blue ) 255 as an integer or a hexadecimal number from 0x00 to 0xFF. imagecolorallocate() must be called to create each color used in the image represented by image. 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 color required. These parameters are 0 to

If allocation fails, it returns -1.

Note:The first call to imagecolorallocate() will fill the background color for the palette-based image, that is, using imagecreate() established image.

Example

<?php
header("Content-type: image/png
$im = @imagecreate(100, 50)
    or die("Unable to initialize a 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 of the output result of the above example is as follows:

Related articles

PHP Image Processing