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, 10 Oct 2008

view this page in

imagechar

(PHP 4, PHP 5)

imagechar水平に文字を描画する

説明

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

imagechar() は、画像 im 上の座標 x ,y (左上が 0, 0) に color 色で c の最初の文字を描画します。

パラメータ

image

imagecreatetruecolor() のような画像作成関数が返す画像リソース。

font

latin2 エンコーディングの組み込みのフォントの場合は 1, 2, 3, 4, 5 のいずれか (数字が大きなほうが、より大きいフォントに対応します)、 あるいは imageloadfont() で登録したフォントの識別子のいずれか。

x

始点の x 座標。

y

始点の y 座標。

c

描画する文字。

color

imagecolorallocate() で作成した色 ID。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 imagechar() の例

<?php

$im 
imagecreate(100100);

$string 'PHP';

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

// 左上の角に黒で "P" を表示します
imagechar($im100$string$black);

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

?>

上の例の出力は、たとえば 以下のようになります。



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, 10 Oct 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites