听说PHP可以不用组件实现~
ASP得装组件``所以我现在ASP的程序打算来采用一个PHP的上传头像代码~
来实现可以生成头像缩略图~麻烦哪个高手能给个代码~

解决方案 »

  1.   

    function resizeimage($img, $wid, $hei,$c,$type="s",$qianzhui)
       {
           $this->srcimg = $img;
           $this->resize_width = $wid;
           $this->resize_height = $hei;
           $this->cut = $c;
       $this->th_path = $qianzhui;
           //图片的类型
           $this->type = substr(strrchr($this->srcimg,"."),1);
           //初始化图象
           $this->initi_img();
           //目标图象地址
            $this -> dst_img($type);
           //--
           $this->width = imagesx($this->im);
           $this->height = imagesy($this->im);
           //生成图象
           $this->newimg();
           ImageDestroy ($this->im);
       }
       function newimg()
       {
           //改变后的图象的比例
           $resize_ratio = ($this->resize_width)/($this->resize_height);
           //实际图象的比例
           $ratio = ($this->width)/($this->height);
           if(($this->cut)=="1")
           //裁图
           {
               if($ratio>=$resize_ratio)
               //高度优先
               {
                   $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
                   imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
                   ImageJpeg ($newimg,$this->dstimg);
               }
               if($ratio<$resize_ratio)
               //宽度优先
               {
                   $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
                   imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio));
                   ImageJpeg ($newimg,$this->dstimg);
               }
           }
           else
           //不裁图
           {
               if($ratio>=$resize_ratio)
               {
                   $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio);
                   imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height);
                   ImageJpeg ($newimg,$this->dstimg);
               }
               if($ratio<$resize_ratio)
               {
                   $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height);
                   imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height);
                   ImageJpeg ($newimg,$this->dstimg);
               }
           }
       }
       //初始化图象
       function initi_img()
       {
           if($this->type=="jpg")
           {
               $this->im = imagecreatefromjpeg($this->srcimg);
           }
           if($this->type=="gif")
           {
               $this->im = imagecreatefromgif($this->srcimg);
           }
           if($this->type=="png")
           {
               $this->im = imagecreatefrompng($this->srcimg);
           }
       }
       //图象目标地址
       function dst_img($type)
       {
          
           $name         = $this->srcimg;
       $n=substr(strrchr($name,"/"),1);
             $this->dstimg = $this->th_path.$n.".".$type.".".$this->type;
     
       }
    }
      

  2.   

    $resizeimage =new resizeimage($attachment,$w,$h,"1",$type,$qianzhui);这是使用方法
      

  3.   

    给你个简单的下载PHP Thumbnailer Class v2.0代码
    地址如下:
    http://www.gen-x-design.com/projects/php-thumbnailer-class/例子代码:
    include("class.Thumbnail.php");
    $tn_image = new Thumbnail("sample.jpg", 300, 300, 0);
    $tn_image->show(); 
      

  4.   

    $resizeimage =new resizeimage($attachment,$w,$h,"1",$type,$qianzhui);
    attachment表示上传后的图片地址,$w表示缩略图的宽,$h是缩略图的高,1表示裁图,$type表示缩略图后缀,如ss.sd.jpg,sd就是后缀,$qianzhui表示缩略图存放地址,这回总明白了饿