Welcome Guest, Not a member yet? Register   Sign In
image resize - memory exhausted
#1

[eluser]velti[/eluser]
hi,
i want to resize images which where uploaded.
I used this function in another website i coded completely by myself and all worked fine with jpg pictures up to 1MB

yesterday i used nearly the same function in a CI controller and files with 200kb+ caused a memory exhaust.

Code:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 10240 bytes) in /Applications/MAMP/htdocs/projekte/hph/system/helpers/image_helper.php on line 80


Quote:function ImageResize($sourcefile, $thumbziel, $new_w, $logo = NULL) {
global $data;
$data['imagememory']['image1'] = memory_get_usage(true);
$sourceinfo = getimagesize($sourcefile);
if($sourceinfo === false) return FALSE;
$data['imagememory']['image2'] = memory_get_usage(true);

if($sourceinfo[2] == 2) $img = imagecreatefromjpeg($sourcefile);
if($sourceinfo[2] == 3) $img = imagecreatefrompng($sourcefile);

$data['imagememory']['image3'] = memory_get_usage(true);
$ow = $sourceinfo[0]; //imagesx($img);
$oh = $sourceinfo[1]; //imagesy($img);

// Set the new width and height
$check_pic = $ow/$oh;
if($check_pic < 1) {
// wenn das bild hochkant ist
$nh = $new_w;
$nw = ceil(($ow/$oh)*$nh);
} else {
$nw = $new_w;
$nh = ceil(($oh/$ow)*$nw);
}
$data['imagememory']['image4'] = memory_get_usage(true);
// Create the new, resized image
$newimg = imagecreatetruecolor($nw,$nh);
imagecopyresampled($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh);
$data['imagememory']['image5'] = memory_get_usage(true);

// Merge a logo to the picture
if(isset($logo)) {
$logo_img = imageCreateFromGif($logo);
$bwidth = $nw;
$bheight = $nh;
$lwidth = imagesx($logo_img);
$lheight = imagesy($logo_img);
$dst_x = $bwidth - ($lwidth + 10); //zielangaben des logos, hier unten rechts
$dst_y = $bheight - ($lheight + 10);
// ImageAlphaBlending($thumbziel, true);
ImageCopyMerge($newimg,$logo_img,$dst_x,$dst_y,0,0,$lwidth,$lheight, 100);
}

imagejpeg($newimg, $thumbziel);
$data['imagememory']['image6'] = memory_get_usage(true);
imagedestroy($img);
imagedestroy($newimg);
$data['imagememory']['image7'] = memory_get_usage(true);
return $data['imagememory'];
}


what can i do to fix this?

btw.: the same occurs with the image_lib->resize function.


Messages In This Thread
image resize - memory exhausted - by El Forum - 01-13-2008, 04:46 PM
image resize - memory exhausted - by El Forum - 01-13-2008, 05:02 PM
image resize - memory exhausted - by El Forum - 01-13-2008, 05:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB