Jump to content

Allowed Memory Size Exhausted?


Jessica

Recommended Posts

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4252 bytes) in /home/www/sites/lifefiles.com/admin/uploadphotos.php on line 41

[code]function resize_image($type, $file, $max_width, $max_height){
    $full_url = $file;
    
    $imageinfo = getimagesize($file);
    $src_width = $imageinfo[0];
    $src_height = $imageinfo[1];
    
    if($src_width > $max_width){
        $divide = $imageinfo[0] / $max_width;
    }
    if($src_height > $max_height){
        $divide = $imageinfo[1] / $max_height;
    }
    
    $dest_width = $src_width / $divide;
    $dest_height = $src_height / $divide;
    
    if($type == 2){
        $src_img = imagecreatefromjpeg($file); (<-- Line 41)
    }else{
        $src_img = imagecreatefromgif($file);
    }
    $dst_img = imagecreatetruecolor($dest_width,$dest_height);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
    if($type == 2){
        imagejpeg($dst_img,$full_url);
    }else{
        imagegif($dst_img,$full_url);
    }
    imagedestroy($src_img);
}
[/code]

The file is a very large one, and I need to be able to do the resize. How do I make it use more memory?
Link to comment
https://forums.phpfreaks.com/topic/11878-allowed-memory-size-exhausted/
Share on other sites

  • 2 years later...
I am on shared hosting but i think i might have figured out some stuff


so i tried my functions again with different images and it worked....

the image that failed was ont 500 kb but had dimension of about 3000x2500

i tried another image that was 1.5MB but on 2000x1900 and it worked.

I think imagecopyfromjpeg() can't handel such large dimensions.  does this make sense?  is there a way around this?

thanks!

grant
[quote author=bluebutterflyofyourmind link=topic=95750.msg972939#msg972939 date=1219542405]
I am on shared hosting but i think i might have figured out some stuff


so i tried my functions again with different images and it worked....

the image that failed was ont 500 kb but had dimension of about 3000x2500

i tried another image that was 1.5MB but on 2000x1900 and it worked.

I think imagecopyfromjpeg() can't handel such large dimensions.  does this make sense?  is there a way around this?

thanks!

grant
[/quote]

Can you send me the image? I'll try playing with it on my own server with an image effects class I made and see if it's your server that's the problem, or if it's the actual function.
here ya go.  just go here and download.

[url=http://grantlucas.com/flower_Version2.jpg]http://grantlucas.com/flower_Version2.jpg[/url]

i tried on another server i rent from and i got the same problem.  deffinately thinking it's the pixel dimensions that are messing things up.
Actually, I test to make sure it's an image and then use:

$this->image = imagecreatefromstring(file_get_contents($filename));

That way I don't need to deal with the different functions.  >_>  It's still your host's limit when it comes down to it though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.