Jump to content

Archived

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

Jessica

Allowed Memory Size Exhausted?

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?

Share this post


Link to post
Share on other sites
Firstly, are you on a shared hosting plan?  Because they often have low memory limits for PHP so the whole server isn't backed up. >_>  Secondly, how big of an image are we talking about here?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Works for my image class that I made. >_>  I think it's your host's memory limit.

Share this post


Link to post
Share on other sites
yikes.  really?  crazy.  i tried it on two different hosts and i'm allowing up to 40 MB uploads.  just run into problems with large dimensions.  does this memory limit have to do with file size or other factors?

Share this post


Link to post
Share on other sites
It has to do with the amount of processing power that loading an image of that size takes.  It has nothing to do with upload size, just memory limit size.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.