用PHP打造完美的柱状图

作者:阿圣(Sfan) 发布于:2009-4-13 23:48 Monday 分类:Web

     在PPC 看到的 一个很不错的柱状图类.

 

  1. /***/ 
  2. $bar = new Bar(500, 300, //长.宽  
  3.                array(600, 300, 30, 500, 400, 250, 350, 360),//数据   
  4.                array('A''B''C''D''E''F''G''H'));//名称  
  5. $bar->setTitle('打造完美柱状图!');//标题  
  6. $bar->stroke();  
  7. /***/ 

点击查看原图

 

标签: PHP

评论(0) 引用(0) 浏览(7944)

签名图插件

作者:阿圣(Sfan) 发布于:2009-4-9 4:27 Thursday 分类:Web

        前段就打算加这个小插件的,一直怕自己写不好。而没有动手。做什么事都是开头难。只要自已用心去做了,就能得到意想不到的收获.

效果图:

 

代码如下:类是小鱼写的。改动了一点点而已。

 

  1. /*数据库连接。。。内容调用略*/       
  2. $a='这也会过去,包括我自己  Sfan20.cn'//第一行自定义信息          
  3. $b=array(日志名A,日志名B,日志名C,日志名D);           
  4. $backKey = mt_rand(1,4);           
  5. //$backKey  = 1;                   
  6. $config = new stdClass();           
  7. $config->font = './images/simfang.ttf';             //字体文件           
  8. $config->backImg = "./images/skin_$backKey.jpg";    //背景图           
  9. $config->borderColor = '009900';                    //边框颜色           
  10. $config->textColor = '333333';                      //文字颜色           
  11. $config->top = 30;                                  //顶部位置           
  12. $config->left = 15;                                 //左部位置           
  13. $config->size = 10;                                 //文字大小                           
  14. $$t2i = new txt2image($config);  
  15. $t2i->show($a,$b);  
  16. class txt2image{  
  17.         // 图像types 对应表  
  18.         protected $types = array(  
  19.                         1 => 'gif',  
  20.                         2 => 'jpg',  
  21.                         3 => 'png',  
  22.                         6 => 'bmp' 
  23.                     );  
  24.     // 参数  
  25.     protected $config;  
  26.       
  27.     // 构造方法  
  28.     public function __construct($config){  
  29.             $this->config = $config;          
  30.     }  
  31.       
  32.     // html2rgb  
  33.     protected function html2rgb($html='000000'){  
  34.             $color['r'] = hexdec(substr($html, 0, 2));  
  35.             $color['g'] = hexdec(substr($html, 2, 2));  
  36.             $color['b'] = hexdec(substr($html, 4, 2));  
  37.             return $color;  
  38.     }  
  39.       
  40.         // imageInfo  
  41.         public function getImageInfo($img){  
  42.                 $info = @getimagesize($img);  
  43.                 if(isset($this->types[$info[2]])){  
  44.                         $info['ext'] = $info['type'] = $this->types[$info[2]];  
  45.                 } else{  
  46.                         $info['ext'] = $info['type'] = 'jpg';  
  47.                 }  
  48.                 $info['type'] == 'jpg' && $info['type'] = 'jpeg';  
  49.                 return $info;  
  50.         }  
  51.           
  52.           
  53.           
  54.         // show  
  55.         public function show($code='TEST'){  
  56.                 // 加载背景图片  
  57.                 $info = $this->getImageInfo($this->config->backImg);  
  58.                 if(!emptyempty($info[0])){  
  59.                         $width = $info[0];  
  60.                         $height = $info[1];  
  61.                         $type  = $info['type'];  
  62.                         $ext   = $info['ext'];  
  63.                         $fun   = 'imagecreatefrom'.$type;  
  64.                         $im = $fun($this->config->backImg);  
  65.                 } else{  
  66.                         $this->error($this->config->backImg.': 背景图片读取失败!');  
  67.                 }  
  68.                 !is_file($this->config->font) && $this->error($this->config->font.': 字体文件读取失败!');  
  69.                   
  70.                 // 设定图像的混色模式   
  71.                 imagealphablending($im, true);           
  72.             // 定义要用到的颜色  
  73.             $b_rgb = $this->html2rgb($this->config->borderColor);  
  74.             $t_rgb = $this->html2rgb($this->config->textColor);  
  75.             $border_color = imagecolorallocate($im$b_rgb['r'], $b_rgb['g'], $b_rgb['b']);  
  76.             $text_color = imagecolorallocate($im$t_rgb['r'], $t_rgb['g'], $t_rgb['b']);  
  77.             // 画边框  
  78.             imagerectangle($im,0,0,$width-1,$height-1,$border_color);  
  79.             // 写文字  
  80.             imagefttext($im$this->config->size , 0, $this->config->left, $this->config->top,  $text_color$this->config->font,$header);                       
  81.             imagefttext($im$this->config->size , 0, $this->config->left, $this->config->top+8,  $text_color$this->config->font,'----------------------------');                       
  82.             foreach($code as $k=>$codes){                         imagefttext($im$this->config->size , 0, $this->config->left, $this->config->top+($k+1)*20,  $text_color$this->config->font,$codes);                       }             
  83.                 // 输出图片PNG  
  84.                 header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");  
  85.                 header("Content-type: image/png");  
  86.                 imagepng($im);  
  87.                 imagedestroy($im);  
  88.         }  
  89.           
  90.         // 抛出错误  
  91.         protected function error($msg='Error!'){  
  92.                 die($msg);          
  93.         }  
  94.           
  95. }  

 

标签: PHP 签名图

评论(0) 引用(0) 浏览(7948)

Blog 增加个代码高亮的插件

作者:阿圣(Sfan) 发布于:2009-4-5 7:39 Sunday 分类:Web

 

    程序原来没有这个功能,只能自己加~原来的Fckedit 是精简过的不能加插件,网上搜了一个。

     测试一下代码高亮的效果: 

  1. <?php    
  2.    echo "hello world";   
  3.  ?>  

       不知不觉天就亮的.....

                 (...刚加上的时候不能显示行号.自己CSS还不怎么会.多谢木头的帮忙~)

标签: PHP

评论(2) 引用(0) 浏览(7908)

个性签名图

作者:阿圣(Sfan) 发布于:2009-4-1 0:11 Wednesday 分类:Web

 

    看了php100的采集程序那集后.自己也整了一个签名图.内容是采集QQ滔滔的内容.刷新切换背景.可以自己自定义QQ号.代码非常垃圾.在这里就不贴出来了.

过几天.试着写一个调用这个blog 文章标题的签名图.

前段时间自己做的一个签名图

ps:由于这个空间限制了一些函数.程序我放到另外的空间了.可能不支持外链.点击这里查看

标签: PHP 签名图

评论(0) 引用(0) 浏览(9013)

Powered by emlog 湘ICP备08103487号