. .

» PHP 5 »

, . , . GD , imagestring() 13.8.

13.8. .

‹?php
header("Content-type: image/png");
$image = imagecreatetruecolor (100, 100);
$white = imagecolorallocate($image, 255, 255, 255);
//
imagestring($image, 3, 5, 49, "Hello, World!", $white);
//
imagepng($image);
//
imagedestroy($image);
?›

Hello, World! . .

, ( 1 5), , , , .

GD . , imagettftext(), TrueType ( 13.9).

13.9. imagettftext()

‹?php
header("Content-type: image/png");
$image = imagecreatetruecolor (100, 100);
$white = imagecolorallocate($image, 255, 255, 255);
//
imagettftext($image, 9, 0, 5, 49, $white, "Snap.ttf", "Hello, World!");
//
imagepng($image);
//
imagedestroy($image);
?›

Snap.ttf, Snap ITC. : , , , , , ( ) .

, . imagefontheight(), imagefontwidth() imagettfbbox().

. , ( 13.10).

13.10. .

‹?php
header("Content-type: image/png");
$image = imagecreatetruecolor (200, 200);
$white = imagecolorallocate($image, 255, 255, 255);
//
$str = "Hello, World!";
//
$ = (200 - strlen($str) * imagefontwidtli(4)) /2;
$ = (200 - imagefontheight(4)) / 2;
//
imagestring($image, 4, $, $, $str, $white);
//
imagepng($image);
//
imagedestroy($image);
?›

. , .

, . imagettfbbox() - 13.11.

13.11. imagettfbbox()

‹?php
header("Content-type: image/png");
$image = imagecreatetruecolor (100, 100);
$white = imagecolorallocate($image, 255, 255, 255);
//
$mas_loc = imagettfbbox(15, 23, "Snap.ttf", "Hello, World!");
//
$ = 100 - ($mas_loc[0] + $mas_loc[2] + $mas_loc[4] + $mas_loc[6]) / 4;
$y = 100 - ($mas_loc[1] + $mas_loc[3] + $mas_loc[5] + $mas_loc[7]) / 4;
//
imagettftext($image,15, 23, $x, $y, $white, "Snap.ttf", "Hello, World!");
//
imagepng($image);
//
imagedestroy($image);
?›

imagettfbbox() , , . , , 13.1.

13.1. .

0 ( )
1 ( Y)
2 ( )
3 ( Y)
4 ( OX)
5 ( OY)
6 ( )
7 ( OY)