1、param($img1)-thumb(./image/test_0.jpg, 200,200,0);/ center center 裁剪$img-param($img1)-thumb(./image/test_1.jpg, 200,200,1);/ top left 裁剪$img-param($img1)-thumb(./image/test_2.jpg, 200,200,2);/ 右下角添加水印$img-param($img1)-water($img2,$water,9);/* +-+* | Copyright (c) 2008-2009 Diqiye.Com All rights rese
2、rved.* +-+* | Info : 图像处理类* +-+*/class image / 当前图片protected $img;/ 图像 types 对应表protected $types = array(1 = gif,2 = jpg,3 = png,6 = bmp);/ imagepublic function _construct($img=)!$img / Infopublic function param($img)$this-img = $img;return $this;/ imageInfopublic function getImageInfo($img)$info =
3、getimagesize($img);if(isset($this-types$info2)$infoext = $infotype = $this-types$info2; else$infoext = $infotype = jpg;$infotype = jpg $infosize = filesize($img);return $info;/ thumb(新图地址, 宽, 高, 裁剪, 允许放大)public function thumb($filename,$new_w=160,$new_h=120,$cut=0,$big=0)/ 获取原图信息$info = $this-getIma
4、geInfo($this-img);if(!empty($info0) $old_w = $info0;$old_h = $info1;$type = $infotype;$ext = $infoext;unset($info);/ 如果原图比缩略图小 并且不允许放大if($old_w $scale2)$end_h = round($old_w/$scale1,2);$start_h = ($old_h-$end_h)/2;$start_w = 0;$end_w = $old_w; else$end_w = round($old_h*$scale1,2);$start_w = ($old_w-
5、$end_w)/2;$start_h = 0;$end_h = $old_h;$width = $new_w;$height= $new_h; elseif($cut = 2) / left top 裁剪$scale1 = round($new_w/$new_h,2);$scale2 = round($old_w/$old_h,2);if($scale1 $scale2)$end_h = round($old_w/$scale1,2);$end_w = $old_w; else$end_w = round($old_h*$scale1,2);$end_h = $old_h;$start_w =
6、 0;$start_h = 0;$width = $new_w;$height= $new_h;/ 载入原图$createFun = ImageCreateFrom.$type;$oldimg = $createFun($this-img);/ 创建缩略图if($type!=gif else$newimg = imagecreate($width, $height);/ 复制图片if(function_exists(“ImageCopyResampled“)ImageCopyResampled($newimg, $oldimg, 0, 0, $start_w, $start_h, $width
7、, $height, $end_w,$end_h); elseImageCopyResized($newimg, $oldimg, 0, 0, $start_w, $start_h, $width, $height, $end_w,$end_h);/ 对 jpeg 图形设置隔行扫描$type = jpeg / 生成图片$imageFun = image.$type;!$imageFun($newimg,$filename) ImageDestroy($newimg);ImageDestroy($oldimg);return $filename;return false;/ water(保存地址
8、 ,水印图片 ,水印位置,透明度)public function water($filename,$water,$pos=0,$pct=80)/ 加载水印图片$info = $this-getImageInfo($water);if(!empty($info0)$water_w = $info0;$water_h = $info1;$type = $infotype;$fun = imagecreatefrom.$type;$waterimg = $fun($water); elsereturn false;/ 加载背景图片$info = $this-getImageInfo($this-im
9、g);if(!empty($info0)$old_w = $info0;$old_h = $info1;$type = $infotype;$fun = imagecreatefrom.$type;$oldimg = $fun($this-img); elsereturn false;/ 剪切水印$water_w $old_w $water_h $old_h / 水印位置switch($pos)case 0:/随机$posX = rand(0,($old_w - $water_w);$posY = rand(0,($old_h - $water_h);break;case 1:/1 为顶端居左
10、$posX = 0;$posY = 0;break;case 2:/2 为顶端居中$posX = ($old_w - $water_w) / 2;$posY = 0;break;case 3:/3 为顶端居右$posX = $old_w - $water_w;$posY = 0;break;case 4:/4 为中部居左$posX = 0;$posY = ($old_h - $water_h) / 2;break;case 5:/5 为中部居中$posX = ($old_w - $water_w) / 2;$posY = ($old_h - $water_h) / 2;break;case 6
11、:/6 为中部居右$posX = $old_w - $water_w;$posY = ($old_h - $water_h) / 2;break;case 7:/7 为底端居左$posX = 0;$posY = $old_h - $water_h;break;case 8:/8 为底端居中$posX = ($old_w - $water_w) / 2;$posY = $old_h - $water_h;break;case 9:/9 为底端居右$posX = $old_w - $water_w;$posY = $old_h - $water_h;break;default: /随机$posX
12、= rand(0,($old_w - $water_w);$posY = rand(0,($old_h - $water_h);break;/ 设定图像的混色模式imagealphablending($oldimg, true);/ 添加水印imagecopymerge($oldimg, $waterimg, $posX, $posY, 0, 0, $water_w,$water_h,$pct);$fun = image.$type;!$fun($oldimg, $filename) imagedestroy($oldimg);imagedestroy($waterimg);return $filename;?