PHP/Graphics Image/Text Align

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

Aligning Text Within a Fixed Space Using imageTTFbbox()

   <source lang="html4strict">

<?php header("Content-type: image/gif"); $height = 100; $width = 200; $fontsize = 50; if ( ! isset ( $text ) )

   $text = "www.wbex.ru";

$image = imagecreate( $width, $height ); $red = imagecolorallocate($image, 255,0,0); $blue = imagecolorallocate($image, 0,0,255 ); $font = "ARIALBD.TTF"; $textwidth = $width; $textheight; while ( 1 ){

   $box = imageTTFbbox( $fontsize, 0, $font, $text );
   $textwidth =  abs( $box[2] );
   $textbodyheight = ( abs($box[7]) )-2;
   if ( $textwidth < $width - 20 )
       break;
   $fontsize--;

} $gifXcenter = (int) ( $width/2 ); $gifYcenter = (int) ( $height/2 ); imageTTFtext($image, $fontsize, 0,(int) ($gifXcenter-($textwidth/2)),(int)($gifYcenter+(($textbodyheight)/2) ),

            $blue, $font, $text );

imagegif($image); ?>

      </source>