Chinaunix首页 | 论坛 | 博客
  • 博客访问: 423736
  • 博文数量: 78
  • 博客积分: 1563
  • 博客等级: 上尉
  • 技术积分: 910
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-25 09:58
个人简介

爬虫

文章分类

全部博文(78)

文章存档

2020年(1)

2016年(1)

2015年(9)

2014年(1)

2013年(8)

2012年(6)

2011年(3)

2010年(4)

2008年(8)

2007年(13)

2006年(24)

我的朋友

分类: Windows平台

2013-10-24 09:50:19

class AddWaterPress{ //定义类文件
function getExtendsName($fileName){ //获取上传图片后缀
   return strtolower(strstr($fileName, ".")); //返回图片后缀
}
function getImageRes($extendsName, $imageUrl){ //根据上传图片的后缀,和上传文件的路径新建图像
switch($extendsName){ //根据上传图片的后缀进行判断
       case '.gif': //如果后缀为gif
        $img =imagecreatefromgif($imageUrl); //则根据路径创建一个GIF图像
break;
            case '.jpg': //如果后缀为jpg
                 $img =imagecreatefromjpeg($imageUrl); //则根据路径创建一个JPG图像
break;
            case '.png': 
                 $img =imagecreatefrompng($imageUrl);
break;
            case '.bmp':
                 $img =imagecreatefromwbmp($imageUrl);
break;
        }  
return $img; //返回创建图像的标识
}


function outputImage($img, $extendsName, $imageUrl){ //根据图像标识、图片后缀和路径输出图像
         switch($extendsName){ //判断图像后缀
        case '.gif': //如果后缀为gif
        imagegif($img, $imageUrl); //则输出img图像
break;
             case '.jpg':
                 imagejpeg($img, $imageUrl);
break;
             case '.png': 
                 imagepng($img, $imageUrl);
break;
             case '.bmp':
                 imagewbmp($img, $imageUrl);
break;
        }               
}

function add($imageUrl, $textinfo){ //定义添加方法
$img = @$this->getImageRes($this->getExtendsName($imageUrl), $imageUrl); //获取被操作的图像标识
      $textcolor=imagecolorallocate($img,0,0,0);  //设置字体颜色为蓝色,值为RGB颜色值
//imagestring($img, 20, 30, 100, "$watherImageUrl", $textcolor);
$fnt="c:/windows/fonts/simhei.ttf";    //定义字体
$text =iconv("gb2312", "utf-8", $textinfo);         //将中文转换为UTF-8格式
imagettftext($img,20,0,30,100,$textcolor,$fnt,$text);    //写TTF文字到图中
    //根据图像标识符、后缀和路径,执行outputImage方法,输出图像
   $this->outputImage($img, $this->getExtendsName($imageUrl), $imageUrl);
        imagedestroy($img);         //销毁图像
}


}




$imageclass=new AddWaterPress();
$imageclass->add("1.jpg","1111");
?>
阅读(780) | 评论(0) | 转发(0) |
0

上一篇:htc 解锁过程

下一篇:bmp转jpeg

给主人留下些什么吧!~~