全球主机交流论坛

标题: 小弟初到贵地,求个PHP的缩略图类 [打印本页]

作者: 360安全卫士    时间: 2012-9-14 17:14
标题: 小弟初到贵地,求个PHP的缩略图类
本帖最后由 360安全卫士 于 2012-9-14 17:15 编辑

要求:
1.有缩略图功能(可指定长宽、或等比)
2.有切割功能(指定切割起始坐标、切割范围)、
3.水印功能(有无均可,此项不强制)

好人一生平安,回此帖者,一人加10分(要在第一页)无关回复扣10分
作者: 软件风暴    时间: 2012-9-14 17:15
哎呦不错啊  
作者: smyz    时间: 2012-9-14 17:16
有,搞过头像上传的基本都有
作者: mix    时间: 2012-9-14 17:16
哎呦不错哦
作者: —。—    时间: 2012-9-14 17:16
LZ说的要求我都需要  求PM
作者: chairo    时间: 2012-9-14 17:16
围观呶呶扣分……
作者: lazyzhu    时间: 2012-9-14 17:16
10分
作者: 狂奔的蜗牛    时间: 2012-9-14 17:17
帮顶
作者: scand    时间: 2012-9-14 17:17
第二个比较难找吧
作者: 360安全卫士    时间: 2012-9-14 17:18
scand 发表于 2012-9-14 17:17
第二个比较难找吧

同样不强制,
作者: tearjoker    时间: 2012-9-14 17:20
来扣分
作者: tearjoker    时间: 2012-9-14 17:21
给艹10分  不给艹 0分
作者: scand    时间: 2012-9-14 17:24
  1. <?php

  2. /*
  3. * Created on 20:31 2011-8-2
  4. * Author : LKK , http://lianq.net
  5. * 使用方法:
  6. *$resizeimage = new myThumbClass($file_name,120,90,$thumb,0,0);  //生成120x90大小
  7. *$resizeimage = new myThumbClass($file_name,1,2,$thumb,1,233);   //生成高,宽之中最大233
  8. *$resizeimage = new myThumbClass($file_name,660,1,$thumb,-1,0);  //生成宽度660
  9. *$resizeimage = new myThumbClass($file_name,1,660,$thumb,-1,0);  //生成高度660
  10. *注意:新高度或新宽度都不能为0
  11. */

  12. class myThumbClass{

  13.         public $sur_file;        //读取的原图片
  14.         public $des_file;        //生成目标图片
  15.         public $tem_file;        //临时图片
  16.         public $tag;                //缩略标签  0,默认,按固定的高宽生成  1,按比列或固定最大长度生成  -1,按某个宽度或某个高度缩小
  17.         public $resize_width;                //$tag为0时,目标文件宽
  18.         public $resize_height;                //$tag为0时,目标文件高
  19.         public $sca_max;        //$tag为1时,<0$sca_max<1时为缩小比例;$sca_max>1时为最大长度(高或宽之中的最大值)

  20.         public $type;                //图片类型
  21.         public $width;                //原图片宽
  22.         public $height;                //原图片高

  23.         //构造函数
  24.         public function __construct($surpic, $reswid, $reshei, $despic, $mark, $scamax){
  25.                 $this->sur_file = $surpic;
  26.                 $this->resize_width = $reswid;
  27.                 $this->resize_height = $reshei;
  28.                 $this->tag = $mark;
  29.                 $this->sca_max = $scamax;

  30.                 $this->type = strtolower(substr(strrchr($this->sur_file,"."),1));        //获取图片类型
  31.                 $this->init_img();        //初始化图片
  32.                 $this->des_file = $despic;        //目标图片地址
  33.                 $this->width = imagesx($this->tem_file);
  34.                 $this->height = imagesy($this->tem_file);
  35.                 $this->new_img();
  36.                 imagedestroy($this->tem_file);
  37.         }

  38.         //图片初始化函数
  39.         private function init_img(){
  40.                 if($this->type == 'jpeg'){
  41.                         $this->tem_file = imagecreatefromjpeg($this->sur_file);
  42.                 }elseif($this->type == 'jpg'){
  43.                         $this->tem_file = imagecreatefromjpeg($this->sur_file);
  44.                 }elseif($this->type == 'gif'){
  45.             $this->tem_file = imagecreatefromgif($this->sur_file);
  46.                 }elseif($this->type == 'png'){
  47.             $this->tem_file = imagecreatefrompng($this->sur_file);
  48.                 }elseif($this->type == 'bmp'){
  49.          //   $this->tem_file = imagecreatefrombmp($this->sur_file);        //bmp.php中包含
  50.                 }
  51.         }

  52.         //图片生成函数
  53.         private function new_img(){
  54.                 $ratio = ($this->width)/($this->height);        //原图比例
  55.                 $resize_ratio = ($this->resize_width)/($this->resize_height);        //缩略后比例
  56.                 $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);//生成新图片

  57.                 if($this->tag == 0){        //按固定高宽截取缩略图
  58.                         $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);//生成新图片
  59.                         if($ratio>=$resize_ratio){//即等比例下,缩略图的高比原图长,因此高不变
  60.                                 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
  61.                         }elseif($ratio<$resize_ratio){//即等比例下,缩略图的宽比原图长,因此宽不变
  62.                                 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width,$this->resize_height, $this->width, (($this->width)/$resize_ratio));
  63.                         }
  64.                 }elseif($this->tag == 1){        //按固定比例或最大长度缩小
  65.                         if($this->sca_max < 1){        //按比例缩小
  66.                                 $newimg = imagecreatetruecolor((($this->width)*($this->sca_max)),(($this->height)*($this->sca_max)));//生成新图片
  67.                                 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, (($this->width)*($this->sca_max)), (($this->height)*($this->sca_max)), $this->width, $this->height);

  68.                         }elseif($this->sca_max > 1){        //按某个最大长度缩小
  69.                                 if($ratio>=1){        //宽比高长
  70.                                         $newimg = imagecreatetruecolor($this->sca_max,($this->sca_max/$ratio));//生成新图片
  71.                                         imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->sca_max,($this->sca_max/$ratio), $this->width, $this->height);
  72.                                 }else{
  73.                                         $newimg = imagecreatetruecolor(($this->sca_max*$ratio),$this->sca_max);//生成新图片
  74.                                         imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, ($this->sca_max*$ratio),$this->sca_max, $this->width, $this->height);
  75.                                 }
  76.                         }
  77.                 }elseif($this->tag == -1){        //按某个宽度或某个高度缩小
  78.                   if($resize_ratio>=1){//新高小于新宽,则图片按新宽度缩小
  79.                     $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width/$ratio));//生成新图片
  80.                         imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width,($this->resize_width/$ratio), $this->width, $this->height);
  81.                   }elseif($resize_ratio<1){//新宽小于新高,则图片按新高度缩小
  82.                     $newimg = imagecreatetruecolor(($this->resize_height*$ratio),$this->resize_height);//生成新图片
  83.                                         imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, ($this->resize_height*$ratio),$this->resize_height, $this->width, $this->height);
  84.                   }
  85.                 }

  86.                 //输出新图片
  87.                 if($this->type == 'jpeg' || $this->type == 'jpg'){
  88.                         imagejpeg($newimg,$this->des_file);
  89.                 }elseif($this->type == 'gif'){
  90.                         imagegif($newimg,$this->des_file);
  91.                 }elseif($this->type == 'png'){
  92.                         imagepng($newimg,$this->des_file);
  93.                 }elseif($this->type == 'bmp'){
  94.                         imagebmp($newimg,$this->des_file);//bmp.php中包含
  95.                 }

  96.         }#function new_img() end

  97. }#end class

  98. ?>
复制代码
这个是我改blog的时候 在网上找的   基本功能有了

作者: ybs885    时间: 2012-9-14 19:48
scand 发表于 2012-9-14 17:24
这个是我改blog的时候 在网上找的   基本功能有了

大牛啊
作者: usa    时间: 2012-9-14 19:53
采集图片 切掉水印...




欢迎光临 全球主机交流论坛 (https://loc.888543.xyz/) Powered by Discuz! X3.4