不知道你研究过 vbb3 的代码没
里面的 图片附件 缩略图 就是用的楼主说的技术
有时间去看看吧 楼主 研究VBB3真不错啊 能学到很多东西建议楼主也加入 VBB3 的研究开发工作中来吧
呵呵

解决方案 »

  1.   

    别的先别说,用imagecopyresized函数缩小了以后,质量变得十分差,有什么办法么?另外,imagecreatefromgd和imagecreatefromgd2怎么在很多机器上都导致死机?(win2000 prof sp4 + apache 2+php 4.3.5)
      

  2.   

    可以用is_string来判断如何使用图片对象。可以用imagecopyresampled来提高清晰度
      

  3.   

    偶在收藏的。看看合合适你
    <? 
    //测试用。
    $FILENAME="filename"; // 生成图片的宽度 
    $RESIZEWIDTH=200; // 生成图片的高度 
    $RESIZEHEIGHT=150; 
    function ResizeImage($im,$maxwidth,$maxheight,$name){ 
    $width = imagesx($im); 
    $height = imagesy($im); 
    if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ 
            if($maxwidth && $width > $maxwidth){ 
                $widthratio = $maxwidth/$width; 
                $RESIZEWIDTH=true; 
            } 
            if($maxheight && $height > $maxheight){ 
                $heightratio = $maxheight/$height; 
                $RESIZEHEIGHT=true; 
            } 
            if($RESIZEWIDTH && $RESIZEHEIGHT)
             { 
                if($widthratio < $heightratio)
                  { 
                          $ratio = $widthratio; 
                  }
              else{ 
                   $ratio = $heightratio; 
                  } 
            }
          elseif($RESIZEWIDTH)
         { 
             $ratio = $widthratio; 
         }elseif($RESIZEHEIGHT)
         { 
            $ratio = $heightratio; 
          } 
    $newwidth = $width * $ratio; 
    $newheight = $height * $ratio; 
    if(function_exists("imagecopyresampled"))

    $newim = imagecreatetruecolor($newwidth, $newheight); 
    imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 
    }else{ 
    $newim = imagecreate($newwidth, $newheight); 
    imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

    ImageJpeg ($newim,$name . ".jpg"); 
    ImageDestroy ($newim); 
    }else{ 
    ImageJpeg ($im,$name . ".jpg"); 
    //ImageDestroy ($newim);


    echo $_FILES['image']['type']."<br>";
    echo $_FILES['image']['size'],"<br>";
    echo $_FILES['image']['tmp_name'],"<br>";
    echo $_FILES['image']['name']."<br>";
    if($_FILES['image']['size'])

       if($_FILES['image']['type'] == "image/pjpeg"){ 
       $im = imagecreatefromjpeg($_FILES['image']['tmp_name']); 
       }elseif($_FILES['image']['type'] == "image/x-png"){ 
       $im = imagecreatefrompng($_FILES['image']['tmp_name']); 
       }elseif($_FILES['image']['type'] == "image/gif"){ 
       $im = imagecreatefromgif($_FILES['image']['tmp_name']); 
       } 
      if($im)
     { 
        if(file_exists("$FILENAME.jpg"))

           unlink("$FILENAME.jpg"); 
        } 
         ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); 
         ImageDestroy ($im); //删除
     }} ?> <img src="<? echo $FILENAME.'.jpg?reload='.rand(0,999999); ?>"><br/><br/> 
    <img src="<? echo $FILENAME.'.jpg?rd='.rand(0,999999); ?>"><br/><br/>
    <form enctype="multipart/form-data" method="post"> 
    <br/> 
    <input type="file" name="image" size="50" ><p> 
    <input type="submit" value="上传图片"> 
    </form>  </body> 
    </html>
    好晚了,想不到搞一两个页面搞了那么晚。睡觉去......