PHP: imagechar - Manual

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: Sat, 27 Jan 2007

view this page in

# imagechar

(PHP 3, PHP 4, PHP 5)

imagechar -- Draw a character horizontally

## Описание

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

imagechar() draws the first character of `c` in the image identified by `image` with its upper-left at `x`,`y` (top left is 0, 0) with the color `color`.

## Список параметров

`image`

  An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().

`font`

  Can be 1, 2, 3, 4, 5 for built-in fonts (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont().

`x`

  x-coordinate of the start

`y`

  y-coordinate of the start

`c`

  The character to draw

`color`

  A color identifier created with imagecolorallocate()

## Возвращаемые значения

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

## Примеры

Пример 1. imagechar() example

`<?php
$im = imagecreate(100, 100);
$string = 'PHP';
$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// prints a black "P" in the top left corner
imagechar($im, 1, 0, 0, $string, $black);
header('Content-type: image/png');
imagepng($im);
?>`

Результатом выполнения данного примера будет что-то подобное:

## Смотрите также

imagecharup()
imageloadfont()

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);
?>`
add a note
imagecharup imagearc

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST