PHP/Graphics Image

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

Set font

<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]."<br>";
    }
                                                                                          
?>
<img src="pic.png" border=0>
</body>
</html>



Set Font size

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



The TrueType Font Bounding Box

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



Use specified font

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



Use TrueType Fonts

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