bellek ile imagecreatefromjpeg sorun

1 Cevap php

Herkese Merhaba Ben imagecreatefromjpeg ile 700KB bir görüntüyü yeniden boyutlandırmak için çalışıyorum.

Ölümcül hata: tükenmiş 25165824 bayt İzin bellek boyutu (9356 bayt ayırmaya çalıştı) Bu hatayı veriyor

First the memory_limit was 8M then we set this to 24 M but then it still gives the error. Is this a memory leak? What could have happened? We restarted apache already.

İşte ilgilenenler için bazı kod:

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") {
    		$image_org=@imagecreatefromgif($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;		
}

}

1 Cevap

Eğer yeterli kadar bellek artırmak ve sizin sizin işleme ile yapıldığında) (siz imagedestroy kullandığınızdan emin olun.

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