PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagecharup> <imagearc
Last updated: Fri, 26 Dec 2008

view this page in

imagechar

(PHP 4, PHP 5)

imagecharDessine un caractère horizontalement

Description

bool imagechar ( resource $image , int $font , int $x , int $y , string $c , int $color )

imagechar() dessine le premier caractère de la chaîne c dans l'image image avec le coin supérieur gauche placé à la position x ,y (le coin en haut à gauche est l'origine (0,0)) avec la couleur color .

Liste de paramètres

image

Une ressource d'image, retourné par une des fonctions de création d'images, comme imagecreatetruecolor().

font

Peut être 1, 2, 3, 4, 5 pour les polices internes d'encodage Latin2 (où les plus grands nombres correspondent aux polices larges) ou n'importe quels identifiants de police de votre choix, enregistrées avec la fonction imageloadfont().

x

X : coordonnée de départ.

y

Y : coordonnée de départ.

c

Le caractère à dessiner.

color

Un identifiant de couleur créé par la fonction imagecolorallocate().

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Exemples

Exemple #1 Exemple avec imagechar()

<?php

$im 
imagecreate(100100);

$string 'PHP';

$bg imagecolorallocate($im255255255);
$black imagecolorallocate($im000);

// affiche un "P" noir dans le coin gauche en haut
imagechar($im100$string$black);

header('Content-type: image/png');
imagepng($im);

?>

L'exemple ci-dessus va afficher quelque chose de similaire à :



add a note add a note User Contributed Notes
imagechar
sw at profilschmiede dot de
20-Jun-2005 06:35
For the sake of completeness, here is an example for imagechar.
The base-image automatically adjusts to the size and the height of the given string. Using the rand()-function the y-position of each char is slightly varied with every loop-run. You can easily rewrite the script to use a randomly generated string - the one given here just serves as an example.

<?php

$string
= '1 2 3 4 5 6 7 8 9 A B C D E F G';
$font_size = 5;
$width=imagefontwidth($font_size)*strlen($string);
$height=imagefontheight($font_size)*2;
$img = imagecreate($width,$height);
$bg = imagecolorallocate($img,225,225,225);
$black = imagecolorallocate($img,0,0,0);
$len=strlen($string);

for(
$i=0;$i<$len;$i++)
{
   
$xpos=$i*imagefontwidth($font_size);
   
$ypos=rand(0,imagefontheight($font_size));
   
imagechar($img,$font_size,$xpos,$ypos,$string,$black);
   
$string = substr($string,1);   
   
}
header("Content-Type: image/gif");
imagegif($img);
imagedestroy($img);
?>

imagecharup> <imagearc
Last updated: Fri, 26 Dec 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites