用PHP打造完美的柱状图
作者:阿圣(Sfan) 发布于:2009-4-13 23:48 Monday 分类:Web
在PPC 看到的 一个很不错的柱状图类.
- /***/
- $bar = new Bar(500, 300, //长.宽
- array(600, 300, 30, 500, 400, 250, 350, 360),//数据
- array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'));//名称
- $bar->setTitle('打造完美柱状图!');//标题
- $bar->stroke();
- /***/
标签: PHP
签名图插件
作者:阿圣(Sfan) 发布于:2009-4-9 4:27 Thursday 分类:Web
前段就打算加这个小插件的,一直怕自己写不好。而没有动手。做什么事都是开头难。只要自已用心去做了,就能得到意想不到的收获.
效果图:
代码如下:类是小鱼写的。改动了一点点而已。
- /*数据库连接。。。内容调用略*/
- $a='这也会过去,包括我自己 Sfan20.cn';//第一行自定义信息
- $b=array(日志名A,日志名B,日志名C,日志名D);
- $backKey = mt_rand(1,4);
- //$backKey = 1;
- $config = new stdClass();
- $config->font = './images/simfang.ttf'; //字体文件
- $config->backImg = "./images/skin_$backKey.jpg"; //背景图
- $config->borderColor = '009900'; //边框颜色
- $config->textColor = '333333'; //文字颜色
- $config->top = 30; //顶部位置
- $config->left = 15; //左部位置
- $config->size = 10; //文字大小
- $$t2i = new txt2image($config);
- $t2i->show($a,$b);
- class txt2image{
- // 图像types 对应表
- protected $types = array(
- 1 => 'gif',
- 2 => 'jpg',
- 3 => 'png',
- 6 => 'bmp'
- );
- // 参数
- protected $config;
- // 构造方法
- public function __construct($config){
- $this->config = $config;
- }
- // html2rgb
- protected function html2rgb($html='000000'){
- $color['r'] = hexdec(substr($html, 0, 2));
- $color['g'] = hexdec(substr($html, 2, 2));
- $color['b'] = hexdec(substr($html, 4, 2));
- return $color;
- }
- // imageInfo
- public function getImageInfo($img){
- $info = @getimagesize($img);
- if(isset($this->types[$info[2]])){
- $info['ext'] = $info['type'] = $this->types[$info[2]];
- } else{
- $info['ext'] = $info['type'] = 'jpg';
- }
- $info['type'] == 'jpg' && $info['type'] = 'jpeg';
- return $info;
- }
- // show
- public function show($code='TEST'){
- // 加载背景图片
- $info = $this->getImageInfo($this->config->backImg);
- if(!emptyempty($info[0])){
- $width = $info[0];
- $height = $info[1];
- $type = $info['type'];
- $ext = $info['ext'];
- $fun = 'imagecreatefrom'.$type;
- $im = $fun($this->config->backImg);
- } else{
- $this->error($this->config->backImg.': 背景图片读取失败!');
- }
- !is_file($this->config->font) && $this->error($this->config->font.': 字体文件读取失败!');
- // 设定图像的混色模式
- imagealphablending($im, true);
- // 定义要用到的颜色
- $b_rgb = $this->html2rgb($this->config->borderColor);
- $t_rgb = $this->html2rgb($this->config->textColor);
- $border_color = imagecolorallocate($im, $b_rgb['r'], $b_rgb['g'], $b_rgb['b']);
- $text_color = imagecolorallocate($im, $t_rgb['r'], $t_rgb['g'], $t_rgb['b']);
- // 画边框
- imagerectangle($im,0,0,$width-1,$height-1,$border_color);
- // 写文字
- imagefttext($im, $this->config->size , 0, $this->config->left, $this->config->top, $text_color, $this->config->font,$header);
- imagefttext($im, $this->config->size , 0, $this->config->left, $this->config->top+8, $text_color, $this->config->font,'----------------------------');
- 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); }
- // 输出图片PNG
- header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
- header("Content-type: image/png");
- imagepng($im);
- imagedestroy($im);
- }
- // 抛出错误
- protected function error($msg='Error!'){
- die($msg);
- }
- }
Blog 增加个代码高亮的插件
作者:阿圣(Sfan) 发布于:2009-4-5 7:39 Sunday 分类:Web
程序原来没有这个功能,只能自己加~原来的Fckedit 是精简过的不能加插件,网上搜了一个。
测试一下代码高亮的效果:
- <?php
- echo "hello world";
- ?>
不知不觉天就亮的.....
(...刚加上的时候不能显示行号.自己CSS还不怎么会.多谢木头的帮忙~)
标签: PHP
个性签名图
作者:阿圣(Sfan) 发布于:2009-4-1 0:11 Wednesday 分类:Web
看了php100的采集程序那集后.自己也整了一个签名图.内容是采集QQ滔滔的内容.刷新切换背景.可以自己自定义QQ号.代码非常垃圾.在这里就不贴出来了.
过几天.试着写一个调用这个blog 文章标题的签名图.
ps:由于这个空间限制了一些函数.程序我放到另外的空间了.可能不支持外链.点击这里查看