PHP头条
热点:

php缩略图类-PHP源码


php代码

=self::$image_h) && (self::$image_w>$width) ){
                 //缩略后宽
                 $small_w=$width;
                 //缩略后高
                 $n=$width*(self::$image_h/self::$image_w);
                 $small_h=round($n);
             }
        }
       //以原图做画布
       $a='imagecreatefrom'.self::$image_ext;
       $original=$a($image);
       //创建小画布
       $litter=imagecreatetruecolor($width,$height);
       //把大图缩略放入画布
       $x=($width-$small_w)/2;
       $y=($height-$small_h)/2;
       if(!$rs=imagecopyresampled($litter,$original,$x,$y,0,0,$small_w,$small_h,self::$image_w,self::$image_h)){return false;}
       //保存路径
       $path=self::image_Dir().self::rand_Name().'.'.self::$image_ext;
       //保存图片
       $keep='image'.self::$image_ext;
       $keep($litter,$path);
       //关闭图片
       imagedestroy($original);
       imagedestroy($litter);
       //返回路径
       return $path=strtr($path,array(ROOT=>''));
     }
    
     //获取图片信息方法
     protected static function image_Info($image){
       if($info=getimagesize($image)){
            //图像的宽
            self::$image_w=$info[0];                    
            //图像的高
            self::$image_h=$info[1];
            //图像的后缀
            $ext=image_type_to_extension($info[2]);
            $ext=ltrim($ext,'.');
            self::$image_ext=$ext;
       }
     }
    
     //生成路径
     protected static function image_Dir(){
       $dir=ROOT.'Data/images/'.date('Y/m/d/',time());
       if(!is_dir($dir)){mkdir($dir,0777,true);}
       return $dir;
     }
     //随机文件名
     protected static function rand_Name(){
      $name=str_shuffle('1234567890qwertyuiopasdfghjklmnbvcxz');
      $name=substr($name,0,7);
      return $name=$name.'_smal';
     }
  }
  
  //测试
  //echo Gd_Thumbnail_Tool::mk_Thumb('啊.jpg');
  //返回效果:Data/images/2013/02/01/ei3ufpr_smal.jpeg

?>

www.phpzy.comtrue/php/35644.htmlTechArticlephp缩略图类-PHP源码 php代码 =self::$image_h) (self::$image_w>$width) ){ //缩略后宽 $small_w=$width; //缩略后高 $n=$width*(self::$image_h/self::$image_w); $small_h=round($n); } } //以原图做画布 $a=imagecreatefrom.self::...

相关文章

PHP之友评论

今天推荐