PHP/Graphics Image/imagettftext — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:05, 26 мая 2010
Draw with form data
<?php
$_GET["size"] = 44;
$_GET["text"] = "Hello, world!";
$size = imagettfbbox($_GET["size"], 0, "ARIAL", $_GET["text"]);
$xsize = abs($size[0]) + abs($size[2]);
$ysize = abs($size[5]) + abs($size[1]);
$image = imagecreate($xsize, $ysize);
$blue = imagecolorallocate($image, 0, 0, 255);
$white = ImageColorAllocate($image, 255,255,255);
imagettftext($image, $_GET["size"], 0, abs($size[0]), abs($size[5]), $white,"ARIAL", $_GET["text"]);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
Outputting Text
<?php
$image = imagecreate(400,300);
$blue = imagecolorallocate($image, 0, 0, 255);
$white = ImageColorAllocate($image, 255,255,255);
$_GET["size"] = 44;
$_GET["text"] = "Hello, world!";
imagettftext($image, $_GET["size"], 15, 50, 200, $white,
"ARIAL", $_GET["text"]);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
Using the imagettftext() Function
<?php
define("WIDTH", 300);
define("HEIGHT", 100);
define("F_SIZE", 40);
define("F_ANGLE", 0);
define("F_FONT", "myfont.ttf");
$img = imagecreate(WIDTH, HEIGHT);
$white = imagecolorallocate($img, 255,255,255);
$black = imagecolorallocate($img, 0,0,0);
$start_x = 10;
$start_y = (int)HEIGHT/2;
$text = "PHP Unleashed";
imagerectangle($img, 0,0,WIDTH-1,HEIGHT-1, $black);
imageTTFtext($img, F_SIZE, F_ANGLE, $start_x,
$start_y, $black, F_FONT, $text);
header("Content-Type: image/png");
imagepng($img);
?>