我看了这个页面http://expert.csdn.net/Expert/topic/2064/2064094.xml?temp=8.533877E-02测试报错:Fatal error: Call to undefined function: imagecreatefromjpeg() 是不是先要装个什么东东吧,求教!

解决方案 »

  1.   


    //---------------------------------------------------------------
    //自动生成图片缩略图  
    // 本函数从源文件取出图象,设定成指定大小,并输出到目的文件 
    // 源文件格式:gif,jpg,jpe,jpeg,png 
    // 目的文件格式:jpg 
    // 参数说明: 
    // 使用示例:makethumb($srcFile,$dstFile,$dstW,$dstH);
    // $srcFile 源文件 
    // $dstFile 目标文件 
    // $dstW 目标图象宽度 
    // $dstH 目标图象高度 
    //-----------------------------------------------------------------
    */
    function makethumb($srcFile,$dstFile,$dstW,$dstH) { 
    $data = GetImageSize($srcFile,&$info); 
    switch ($data[2]) { 
    case 1: 
      $im = @ImageCreateFromGIF($srcFile); //从目标图片中取出图形
      break; 
    case 2: 
      $im = @imagecreatefromjpeg($srcFile); 
      break; 
    case 3: 
      $im = @ImageCreateFromPNG($srcFile); 
      break; 

    $srcW=ImageSX($im); //取出图片的宽度
    $srcH=ImageSY($im); //取出图片的长度
    $dstX=0; 
    $dstY=0; 
    if ($srcW*$dstH>$srcH*$dstW) 

      $fdstH=round($srcH*$dstW/$srcW); 
      $dstY=floor(($dstH-$fdstH)/2); 
      $fdstW=$dstW; 
    }
    else{ 
      $fdstW=round($srcW*$dstH/$srcH); 
      $dstX=floor(($dstW-$fdstW)/2); 
      $fdstH=$dstH;
      } 
    $ni=ImageCreate($dstW,$dstH); 
    $dstX=($dstX<0)?0:$dstX; 
    $dstY=($dstX<0)?0:$dstY; 
    $dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX; 
    $dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY; 
    $black = ImageColorAllocate($ni, 0,0,0);//填充的背景色你可以重新指定,我用的是黑色 
    imagefilledrectangle($ni,0,0,$dstW,$dstH,$black); 
    ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH); 
    ImageJpeg($ni,$dstFile);//如果你要把图片直接输出到浏览器, 
    //那么把第二个参数去掉,并用header()函数指定mine类型先 
    imagedestroy($im); 
    imagedestroy($ni);
    }
    例子:
    /*
    ----------------------------------------------------
        功能:自动生成图片缩略图
    使用示例:makethumb($srcFile,$dstFile,$dstW,$dstH);
    $srcFile 源文件 
    $dstFile 目标文件 
     $dstW 目标图象宽度 
    $dstH 目标图象高度 ----------------------------------------------------if(!empty($up_file))
    {
    $srcFile=$up_file;
    $dstFile="companys_images/$account/small_images/$imgname";
    $dstW="150";
    $dstH="100";
    makethumb($srcFile,$dstFile,$dstW,$dstH);
    //echo "$srcFile<br>";
    //echo $dstFile;
    }*/
    /*
    else
    {
    // 如果没有上传文件,则图片名为空 
    $filename='';
    echo "你还没上传图片";
    }
    */
      

  2.   

    yykforever(月如钩)你的机子装了gd库了没有?
      

  3.   

    to : xinyaoxp(henonybee) gif可以嘛?
      

  4.   

    //---------------------------------------------------------------
    //自动生成图片缩略图  
    // 本函数从源文件取出图象,设定成指定大小,并输出到目的文件 
    // 源文件格式:gif,jpg,jpe,jpeg,png 
    // 目的文件格式:jpg 
    // 参数说明: 
    // 使用示例:makethumb($srcFile,$dstFile,$dstW,$dstH);
    // $srcFile 源文件 
    // $dstFile 目标文件 
    // $dstW 目标图象宽度 
    // $dstH 目标图象高度 
    //-----------------------------------------------------------------
    */
    function makethumb($srcFile,$dstFile,$dstW,$dstH) { 
    $data = GetImageSize($srcFile,&$info); 
    switch ($data[2]) { 
    case 1: 
      $im = @ImageCreateFromGIF($srcFile); //从目标图片中取出图形
      break; 
    case 2: 
      $im = @imagecreatefromjpeg($srcFile); 
      break; 
    case 3: 
      $im = @ImageCreateFromPNG($srcFile); 
      break; 

    $srcW=ImageSX($im); //取出图片的宽度
    $srcH=ImageSY($im); //取出图片的长度
    $dstX=0; 
    $dstY=0; 
    if ($srcW*$dstH>$srcH*$dstW) 

      $fdstH=round($srcH*$dstW/$srcW); 
      $dstY=floor(($dstH-$fdstH)/2); 
      $fdstW=$dstW; 
    }
    else{ 
      $fdstW=round($srcW*$dstH/$srcH); 
      $dstX=floor(($dstW-$fdstW)/2); 
      $fdstH=$dstH;
      } 
    $ni=ImageCreate($dstW,$dstH); 
    $dstX=($dstX<0)?0:$dstX; 
    $dstY=($dstX<0)?0:$dstY; 
    $dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX; 
    $dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY; 
    $black = ImageColorAllocate($ni, 0,0,0);//填充的背景色你可以重新指定,我用的是黑色 
    imagefilledrectangle($ni,0,0,$dstW,$dstH,$black); 
    ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH); 
    ImageJpeg($ni,$dstFile);//如果你要把图片直接输出到浏览器, 
    //那么把第二个参数去掉,并用header()函数指定mine类型先 
    imagedestroy($im); 
    imagedestroy($ni);
    }
    例子:
    /*
    ----------------------------------------------------
        功能:自动生成图片缩略图
    使用示例:makethumb($srcFile,$dstFile,$dstW,$dstH);
    $srcFile 源文件 
    $dstFile 目标文件 
     $dstW 目标图象宽度 
    $dstH 目标图象高度 ----------------------------------------------------if(!empty($up_file))
    {
    $srcFile=$up_file;
    $dstFile="companys_images/$account/small_images/$imgname";
    $dstW="150";
    $dstH="100";
    makethumb($srcFile,$dstFile,$dstW,$dstH);
    //echo "$srcFile<br>";
    //echo $dstFile;
    }*/
    /*
    else
    {
    // 如果没有上传文件,则图片名为空 
    $filename='';
    echo "你还没上传图片";
    }
    */
      

  5.   

    楼主,去这里看看吧,也许对你会有所帮助
    http://www.phpx.com/happy/showthread.php?s=&threadid=1718
      

  6.   

    function ResizeImage($image,$newname)
    {
    global $etn_config; $maxwidth = $etn_config['resize_width'];
    $maxheight = $etn_config['resize_height'];
    $name = $etn_config['uploadpath'].$newname;
        
    $width = imagesx($image);
        $height = imagesy($image);    if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
            if($maxwidth && $width > $maxwidth){
                $widthratio = $maxwidth/$width;
                $reWidth=true;
            }
            if($maxheight && $height > $maxheight){
                $heightratio = $maxheight/$height;
                $reHeight=true;
            }
            if($reWidth && $reHeight){
                if($widthratio < $heightratio){
                    $ratio = $widthratio;
                }else{
                    $ratio = $heightratio;
                }
            }elseif($reWidth){
                $ratio = $widthratio;
            }elseif($reHeight){
                $ratio = $heightratio;
            }
            $newwidth = $width * $ratio;
            $newheight = $height * $ratio;        if(function_exists("imagecopyresampled")){ //this function needs GD 2.0.1 or later.
                  $newim = imagecreatetruecolor($newwidth, $newheight);
                  imagecopyresampled($newim, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 
            }else{
                $newim = imagecreate($newwidth, $newheight);
                imagecopyresized($newim, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
            }
            ImageJpeg ($newim,$name);
            ImageDestroy ($newim);
        }else{
            ImageJpeg ($image,$name);
        }
    }
      

  7.   

    到www.btph.com看看,这个生成缩略图用的是ImageMagic
      

  8.   

    http://www.51base.com/article/view_article.asp?id=20159http://www.51base.com/article/view_article.asp?id=3594
      

  9.   

    http://www.51base.com/article/view_article.asp?id=25618
      

  10.   

    uphttp://www.51base.com/article/view_article.asp?id=25618