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

Online Tools

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

Object Fonction

Traitement d'image PHP

PHP imagecolorallocate() Fonction d'attribution de couleur à une image, utilisation et exemple

imagecolorallocate — Attribuer une couleur à une image.

Syntaxe

int imagecolorallocate ( resource $image , int $red , int $green , int $blue ) 255 un entier ou un hexadécimal de 0x00 à 0xFF. imagecolorallocate() doit être appelé pour créer chaque couleur utilisée dans l'image représentée par image.

Si l'attribution échoue, elle renverra -1.

Attention :La première appel à imagecolorallocate() remplira le fond de l'image basée sur le panneau de couleurs, c'est-à-dire en utilisant imagecreate() image créée.

Exemple

<?php
header("Content-type: image/png
$im = @imagecreate(100, 50)
    ou die("Impossible d'initialiser un nouveau flux d'image GD");
$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);
?>

Voici l'image du résultat de l'exemple ci-dessus :

Articles associés

Traitement d'image PHP