PHP/Graphics Image

Материал из Web эксперт
Версия от 10:05, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Set font

   <source lang="html4strict">

<html> <body> <?php

   $img=ImageCreate(300,300);
   $bgcolor=ImageColorAllocate($img,200,200,200);
   $red=ImagecolorAllocate($img,255,0,0); 
   $green=ImagecolorAllocate($img,0,255,0); 
   $blue=ImagecolorAllocate($img,0,0,255); 
   $grey=ImagecolorAllocate($img,50,50,50); 
   $black=ImagecolorAllocate($img,0,0,0); 
                                                           
   for($i=0;$i<10;$i++) {
      ImageChar($img,$i,20,20+($i*20),"S",$red);
      $height[]=Imagefontheight($i);
      $width[]=Imagefontwidth($i);
   }
   /*
   RGB Red = 0..255 , Green = 0..255 , Blue = 0..255.
   */
                                                           
   ImageSetPixel($img,50,50,$pixelcolor);
   ImagePNG($img,"pic.png");
   ImageDestroy($img);
   for ($i=0;$i<10;$i++) {
     echo "font ".$i." height=".$height[$i]."
"; }

?> <img src="pic.png" border=0> </body> </html>

      </source>
   
  


Set Font size

   <source lang="html4strict">

<?php $textImage = imagecreate(200,100); $white = imagecolorallocate($textImage, 255, 255, 255); $black = imagecolorallocate($textImage, 0, 0, 0); $yOffset = 0; for ($i = 1; $i <=5; $i++) {

imagestring($textImage, $i, 5, $yOffset, "www.wbex.ru $i", $black);
$yOffset += imagefontheight($i);

} header("Content-type: image/png"); imagepng($textImage); imagedestroy($textImage); ?>

      </source>
   
  


The TrueType Font Bounding Box

   <source lang="html4strict">

<?php

    header ("Content-type: image/png");
  
    $font_size = 15;
    $im = ImageCreate (300, 500);
    $grey = ImageColorAllocate ($im, 230, 230, 230);
    $black = ImageColorAllocate ($im, 0, 0, 0);
    $bbox = ImageTTFBBox($font_size, 0, "ARIALBD.TTF", "Bounding Box!");
  
    for($i = 0; $i < 7; $i++){
         ImageTTFText($im, $font_size, 0, 10, ($i * ($font_size * 2)) + 25,$black, "ARIALBD.TTF", "\$bbox[$i] = $bbox[$i]");
    }
    ImagePng ($im);
    ImageDestroy ($im);

?>

      </source>
   
  


Use specified font

   <source lang="html4strict">

<?php header("Content-type: image/gif"); $image = imagecreate( 400, 200 ); $red = imagecolorallocate($image, 255,0,0); $blue = imagecolorallocate($image, 0,0,255 ); $font = "ARIALBD.TTF"; imageTTFtext( $image, 50, 0, 20, 100, $blue, $font, "www.wbex.ru" ); imagegif($image); ?>

      </source>
   
  


Use TrueType Fonts

   <source lang="html4strict">

<?php

    header ("Content-type: image/png");
  
    $im = ImageCreate (300, 40);
    $grey = ImageColorAllocate ($im, 230, 230, 230);
    $black = ImageColorAllocate ($im, 0, 0, 0);
  
    ImageTTFText($im, 20, 0, 10, 25, $black, "ARIALBD.TTF", "TrueType Fonts!");
    ImagePng ($im);
    ImageDestroy ($im);

?>

      </source>