您的位置:首页 > 编程语言 > PHP开发

【学习点滴-php】用GD库做个简单的进度条

2011-10-28 16:21 232 查看
<?php
// 创建图像
 $imgname="aa.png";
 $image = imagecreatefrompng($imgname); 
 $text = '学习进度概况';

 $red = imagecolorallocate($image, 235, 20, 20); 
 //imagestring($image, 5, 0, 0, $text, $red);
 $font = 'new.ttc';
 imagettftext($image, 20, 0, 100, 40, $red, $font, $text);
 
 $big = array(80,90,280,90,280,130,80,130);
 //imagefilledpolygon($image, $big, 4, $red);
 imageline($image,80,90,280,90,$red);
 imageline($image,280,90,280,130,$red);
 imageline($image,280,130,80,130,$red);
 imageline($image,80,130,80,90,$red); 
 
 $big = array(80,90,200,90,200,130,80,130);
 imagefilledpolygon($image, $big, 4, $red);
 
 $string = "60%";
 for($i=1;$i<=5;$i++){
   imagestring($image, 3, 80+49*($i-1), 75, "$i", $red);
 }
 
 imagestring($image, 20, 290, 100, $string, $red);
 
 $date = date("Y-m-d");
 $dateinfo = "时间:$date";
 imagettftext($image, 10, 0, 130, 160, $red, $font, $dateinfo);

// 输出图像
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>


当然实际中还需要把相应的数据做成动态的,而不是死的。

这只是简单的示例。

效果图:


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: