<?php
header("Content-type: image/gif");
$cells = array ("A"=>1275,"B"=>1312,"C"=>17 ,"D"=>200);
$max = max( $cells );
$total = count ( $cells );
$totalwidth = 556;
$totalheight = 120;
$xgutter = 100; // left/right margin
$ygutter = 20; // top/bottom margin
$internalgap = 10; // space between cells
$bottomspace = 30; // gap at the bottom (in addition to margin)
if(!isset($font))
$font = "C:\Windows\Fonts\arial.ttf";
$graphCanX = ( $totalwidth - $xgutter*2 );
$graphCanY = ( $totalheight - $ygutter*2 - $bottomspace );// starting draw position x - axis
$posX = $xgutter; // starting draw pos - y - axis
$posY = $totalheight - $ygutter - $bottomspace;
$cellwidth = (int) (( $graphCanX - ( $internalgap * ( $total-1 ) )) / $total) ;
$textsize = (int)($bottomspace);
// adjust font size
while ( list( $key, $val ) = each ( $cells ) )
{
while ( 1 )
{
$box = imagettfbbox($textsize,0,$font,$key );
$textWidth = abs( $box[2] );
if ( $textWidth < $cellwidth )
break;
$textsize--;
}
}
$image = imagecreate( $totalwidth, $totalheight );
$red = imagecolorallocate($image, 224, 224, 224);
$blue = imagecolorallocate($image, 0, 0, 255 );
$black = imagecolorallocate($image, 0, 0, 0 );
$grey = imagecolorallocate($image, 100, 100, 100 );
reset ($cells);
while ( list( $key, $val ) = each ( $cells ) )
{
$cellheight = (int) (($val/$max) * $graphCanY);
$center = (int)($posX+($cellwidth/2));
imagefilledrectangle( $image, $posX, ($posY-$cellheight), ($posX+$cellwidth), $posY, $blue );
$box = imagettfbbox( $textsize, 0, $font, $key );
$tw = $box[2];
imagettftext( $image, $textsize, 0, ($center-($tw/2)),
($totalheight-$ygutter), $black, $font, $key );
$posX += ( $cellwidth + $internalgap);
}
imagegif($image);
?>
function.imagettfbbox]: Invalid font filename in do đường dẫn đến file .ttf sai
10/08/2010
Subscribe to:
Post Comments (Atom)
List
Profiles Information
About me : Nothing is 1 vài thứ - 1985
Places I've Lived : I ♥ Hà Nội
Home Page : http://www.shimivn.blogspot.com/
Think : 1:1000000000
Languages spoken : Vietnamese,English.
Mobile : sony C2305 ♥ ♥
dell : i3-Ram 3GB- HDD 250GB . ♥♥♥
Places I've Lived : I ♥ Hà Nội
Home Page : http://www.shimivn.blogspot.com/
Think : 1:1000000000
Languages spoken : Vietnamese,English.
Mobile : sony C2305 ♥ ♥
dell : i3-Ram 3GB- HDD 250GB . ♥♥♥
No comments: