|
imagechar
Draw a character horizontally
(PHP 4, PHP 5)
Example 987. imagechar() example<?php The above example will output something similar to: Related Examples ( Source code ) » imagechar Examples ( Source code ) » Draw char with color Examples ( Source code ) » Set font Code Examples / Notes » imagecharsw
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); ?> |
Change Languagegd_info getimagesize image_type_to_extension image_type_to_mime_type image2wbmp imagealphablending imageantialias imagearc imagechar imagecharup imagecolorallocate imagecolorallocatealpha imagecolorat imagecolorclosest imagecolorclosestalpha imagecolorclosesthwb imagecolordeallocate imagecolorexact imagecolorexactalpha imagecolormatch imagecolorresolve imagecolorresolvealpha imagecolorset imagecolorsforindex imagecolorstotal imagecolortransparent imageconvolution imagecopy imagecopymerge imagecopymergegray imagecopyresampled imagecopyresized imagecreate imagecreatefromgd2 imagecreatefromgd2part imagecreatefromgd imagecreatefromgif imagecreatefromjpeg imagecreatefrompng imagecreatefromstring imagecreatefromwbmp imagecreatefromxbm imagecreatefromxpm imagecreatetruecolor imagedashedline imagedestroy imageellipse imagefill imagefilledarc imagefilledellipse imagefilledpolygon imagefilledrectangle imagefilltoborder imagefilter imagefontheight imagefontwidth imageftbbox imagefttext imagegammacorrect imagegd2 imagegd imagegif imagegrabscreen imagegrabwindow imageinterlace imageistruecolor imagejpeg imagelayereffect imageline imageloadfont imagepalettecopy imagepng imagepolygon imagepsbbox imagepsencodefont imagepsextendfont imagepsfreefont imagepsloadfont imagepsslantfont imagepstext imagerectangle imagerotate imagesavealpha imagesetbrush imagesetpixel imagesetstyle imagesetthickness imagesettile imagestring imagestringup imagesx imagesy imagetruecolortopalette imagettfbbox imagettftext imagetypes imagewbmp imagexbm iptcembed iptcparse jpeg2wbmp png2wbmp |