2009-05-25 105 views
1

大家好,我正在尝试使用imagecreatefromjpeg调整700kb的图像大小。imagecreatefromjpeg内存问题

这给了错误:致命错误:用尽25165824个字节允许内存大小(试图分配9356个字节)

首先memory_limit的是8M然后我们设置这个24米,但随后仍然给出了错误。 这是内存泄漏吗?发生了什么事?我们已经重启了apache。

这里是那些有兴趣谁一些代码:

function getResizedBackgroundImageURL($afb="",$params="") { 
#1. Verwijder webroot 
$filename=C_Settings::getFileRoot().str_replace(C_Settings::getWebRoot(),"",$afb); 
$i=strrpos($filename,"."); 
if ($i!==FALSE) { 
    $ext=substr($filename,$i); 
    $basefilename=substr($filename,0,$i); 

    #Parse width/height params 
    $a=explode("&",$params); 
    foreach($a as $attr) { 
     $b=explode("=",$attr); 
     if ($b[0]=="w") { 
      $w=$b[1]; 
     } elseif ($b[0]=="h") { 
      $h=$b[1]; 
     } 
    } 

    if (!is_numeric($w)) { 
     die("Missing param w for getResizedBackgroundImageURL"); 
    } 

    if (!is_numeric($h)) { 
     die("Missing param h for getResizedBackgroundImageURL"); 
    } 

    #Compose new filename 
    $newFilename=$basefilename."_w".$w."_h".$h.$ext; 
    #See if the resized image exists 
    if (!file_exists($newFilename)) { 
    if (is_file($filename)) { 
     if($ext==".jpg" || $ext==".jpeg"){ 

      $image_org=imagecreatefromjpeg($filename); 


     } 
     if($ext==".gif") { 
      [email protected]($filename); 
     } 

     if ($image_org) { 
      list($wp,$hp,$type,$attr)=getimagesize($filename); 
      $hfactor=$hp/$h; 
      $wfactor=$wp/$w; 
      if ($hfactor > $wfactor) { 
      $factor=$hfactor; 
     } else { 
      $factor=$wfactor; 
     } 
       if($wp > $w || $hp > $h) { 
     $image_w=$wp/$factor; 
     $image_h=$hp/$factor; 
     }else{ 
      #if image fits the given boundaries, do not resize 
      $image_w=$wp; 
     $image_h=$hp;    
     } 
     //Note: PHP with GD2.0 required for imagecreatetruecolor 
     $img_copy=imagecreatetruecolor($image_w, $image_h); 
     imagecopyresampled($img_copy, $image_org, 0, 0, 0, 0, $image_w, $image_h, $wp, $hp); 

      if (@imagejpeg($img_copy, $newFilename, 80)) { 
       chmod($newFilename,0777); 
      } else { 
       echo("<b>Error: </b>Unable to create image $newFilename. Check directory permissions."); 
      } 

      imagedestroy($image_org); 
      imagedestroy($img_copy); 
    } 
    }  
    } 
    $newURL=C_Settings::getWebRoot().str_replace(C_Settings::getFileRoot(),"",$newFilename); 
    return $newURL;  
} 

}

+0

你能展示一些代码吗? – 2009-05-25 09:35:24

+0

我加了一些代码 – sanders 2009-05-25 09:37:40

回答

8

提高你的记忆,直到你有足够的,并确保您使用imagedestroy()当你与你的处理完成。

ini_set("memory_limit","10000M");