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

search for in the

imagecharup> <imagearc
Last updated: Fri, 04 Jul 2008

view this page in

imagechar

(PHP 4, PHP 5)

imagechar — Stellt ein Zeichen horizontal dar

Beschreibung

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

imagechar() stellt das erste in c enthaltene Zeichen in der mit image angegebenen Grafik dar. Das Zeichen wird mit seiner linken oberen Ecke in x , y positionier (die linke obere Ecke der Grapfik hat die Koordinaten 0,0), die Darstellung erfolgt in der Farbe color

Parameter-Liste

image

Eine von den verschiedenen Erzeugungsfunktionen wie imagecreatetruecolor() gelieferte Grafikresource.

font

Ein Wert zwischen 1 und 5 für eingebaute Schriftarten in Latin2 kodierung (wobei größere Werte größeren Schriften entsprechen) oder einer Ihrer mit imageloadfont() selbst registrierten Schrifteinträge.

x

x-Koordinate des Startpunkts

y

y-Koordinate des Startpunkts

c

Das darzustellende Zeichen

color

Eine mittels imagecolorallocate() erstellte Farbe

Rückgabewerte

Gibt bei Erfolg TRUE zurück, im Fehlerfall FALSE.

Beispiele

Beispiel #1 imagechar() Beispiel

<?php

$im 
imagecreate(100100);

$string 'PHP';

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

// schreibe ein schwarzes "P" in die linke obere Ecke 
imagechar($im100$string$black);

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

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:



add a note add a note User Contributed Notes
imagechar
sw at profilschmiede dot de
20-Jun-2005 08: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, 04 Jul 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites