签名图插件 [Web]
post by 阿尚(Sfan) / 2009-4-9 4:27 Thursday
前段就打算加这个小插件的,一直怕自己写不好。而没有动手。做什么事都是开头难。只要自已用心去做了,就能得到意想不到的收获.
效果图:

代码如下:类是小鱼写的。改动了一点点而已。
-
- $a='这也会过去,包括我自己 Sfan20.cn';
- $b=array(日志名A,日志名B,日志名C,日志名D);
- $backKey = mt_rand(1,4);
-
- $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{
-
- protected $types = array(
- 1 => 'gif',
- 2 => 'jpg',
- 3 => 'png',
- 6 => 'bmp'
- );
-
- protected $config;
-
-
- public function __construct($config){
- $this->config = $config;
- }
-
-
- 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;
- }
-
-
- 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;
- }
-
-
-
-
- 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); }
-
- 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);
- }
-
- }
标签: PHP 签名图
发表评论: