<?php
  Header("Content-type:   image/PNG");    
  $im   =   imagecreate(300,50);    
  $bkg   =   ImageColorAllocate($im,   128,64,225);    
  $clr   =   ImageColorAllocate($im,   255,255,255);    
  $fnt   =   "c:/windows/fonts/simfang.ttf";   //   ttf字库的绝对路径  
  $str   =   iconv("GB2312","UTF-8","欢迎光临");   //   转换成utf-8编码，需加载iconv函数库。PHP   ver   >=   4.3.0  
  ImageTTFText($im,   20,   0,   30,40,   $clr,   $fnt,   $str);    
  ImagePNG($im);    
  ImageDestroy($im);  

function createImage($data,$twidth,$tspace,$height){
            $dataName = array();
            $dataValue = array();
            $i = 0;
            $j = 0;
            $k = 0;
            $num = sizeof($data);
            
             foreach($data as $key => $val){
                    $dataName[] = $key;
                    $dataValue[] = $val;
                 }
    
            $maxnum = max($data);
			$tempmun=ceil($maxnum/$height)*10;
            $width = ($twidth + $tspace) * $num + 4;//image's width
            $im = imagecreate($width + 40,$height+20);
            $lineColor = imagecolorallocate($im,12,12,12);
            $bgColor = imagecolorallocate($im,255,255,255);
            $tColor = imagecolorallocate($im,123,200,56);
            imagefill($im,0,0,$bgColor);
            imageline ( $im, 30, 0, 30, $height - 2, $lineColor);
            imageline ( $im, 30, $height -2, $width + 30 -2 , $height -2,$lineColor);
             while($i < $num){
                imagefilledrectangle ( $im, $i * ($tspace+$twidth) + 40, ceil($height-$height*($dataValue[$i]/($tempmun*40))), $i * ($tspace+$twidth) + 40 + $twidth, $height - 3, $tColor);
			   // imagefilledrectangle ( $im, $i * ($tspace+$twidth) + 40, $height - $dataValue[$i], $i * ($tspace+$twidth) + 40 + $twidth, $height - 3, $tColor);
               // imagestring ( $im, 4, $i * ($tspace+$twidth) + $twidth/2 + 30, $height - $dataValue[$i], $dataName[$i]."(".$dataValue[$i].")", $lineColor);
				imagestring ( $im, 4, $i * ($tspace+$twidth) + $twidth/2 + 20, ceil($height-$height*($dataValue[$i]/($tempmun*40))), $dataValue[$i], $lineColor);
				//imagestring ( $im, 3, $i * ($tspace+$twidth) + $twidth/2+15, $height , $dataName[$i], $lineColor);
				imagettftext($im,3,0,20,20,$lineColor,"/path/arial.ttf",$dataName[$i] );
                $i++;
             }
             while($j <= ($height/10)){
			 
                imagestringup ( $im, 4, 2, $height - $j * 10 + 40, $j * $tempmun, $lineColor);
                $j = $j + 8;
             }
             while($k <= ($height/10)){
                 if($k != 0)
                imageline ( $im, 28, $height - $k * 10, 32 , $height - $k * 10,$lineColor);
                $k = $k + 8;
             }
            imagepng($im);
         }

//header("content-type:image/jpeg");
//$data = array("Yahoo" => 100, "Google" => 260,"Microsoft" => 320,"IBM" => 250,"Sun System" => 150,"Inter" => 220);
//createImage($data,40,30,400);


 

?>