Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.