imagecolorallocate

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolorallocateAllocate a color for an image

Descrizione

imagecolorallocate(
    GdImage $image,
    int $red,
    int $green,
    int $blue
): int|false

Returns a color identifier representing the color composed of the given RGB components.

imagecolorallocate() must be called to create each color that is to be used in the image represented by image.

Nota:

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

Elenco dei parametri

image

Una risorsa immagine, restituita da una delle funzioni di creazione immagine, come imagecreatetruecolor().

red

Valore della componente rossa.

green

Valore della componente verde.

blue

Valore della componente blu.

These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF.

Valori restituiti

A color identifier or false if the allocation failed.

Avviso

Questa funzione può restituire il Booleano false, ma può anche restituire un valore non-Booleano valutato come false. Fare riferimento alla sezione Booleans per maggiori informazioni. Usare l'operatore === per controllare il valore restituito da questa funzione.

Log delle modifiche

Versione Descrizione
8.0.0 image expects a GdImage instance now; previously, a valid gd resource was expected.

Esempi

Example #1 imagecolorallocate() example

<?php

$im
= imagecreate(100, 100);

// sets background to red
$background = imagecolorallocate($im, 255, 0, 0);

// sets some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// hexadecimal way
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);

?>

Vedere anche: