PHP/Graphics Image/imagettftext

Материал из Web эксперт
Перейти к: навигация, поиск

Draw with form data

   <source lang="html4strict">

<?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);

?>

 </source>
   
  


Outputting Text

   <source lang="html4strict">

<?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);

?>

 </source>
   
  


Using the imagettftext() Function

   <source lang="html4strict">

<?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);

?>

 </source>