Jump to content


Photo

Allowed Memory Size Exhausted?


  • Please log in to reply
13 replies to this topic

#1 Jessica

Jessica
  • Staff Alumni
  • This is not my name.
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 13 June 2006 - 03:07 PM

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

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); 
}

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?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#2 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 01:03 AM

I have the same problem.  though this is happening on relatively small files. ie: <1MB  not sure how to fix this. neone?

#3 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 24 August 2008 - 01:43 AM

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?
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#4 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 01:46 AM

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

#5 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 24 August 2008 - 01:49 AM

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


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.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#6 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 02:00 AM

here ya go.  just go here and download.

http://grantlucas.co...er_Version2.jpg

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.

#7 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 24 August 2008 - 02:05 AM

Works for my image class that I made. >_>  I think it's your host's memory limit.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#8 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 02:07 AM

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?

#9 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 24 August 2008 - 02:08 AM

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.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#10 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 02:11 AM

hm that sucks.  so it's NOT a problem having to do with the imagecopyjpeg() function?  is that what you used as well?

#11 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 24 August 2008 - 02:17 AM

You mean imagecreatefromjpeg()?
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#12 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 02:20 AM

yeah

#13 DarkWater

DarkWater
  • Members
  • PipPipPip
  • Advanced Member
  • 6,175 posts
  • LocationNew York

Posted 24 August 2008 - 02:25 AM

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.
Info:Apache 2.2.4 | PHP 6.0.0-dev, PHP 5.2.4 | Ubuntu 8.04 | Age: 16 | Coding PHP and CSS+(X)HTML: 5-6 years | Feel free to PM me if you need help!
Αν χρειάζεσαι ένας μεταφραστής, μπορέις να μου μιλάς.  Μιλώ καλά.

If you ask for a banana, would you expect someone to hand you an orange? Or a fork?  No you wouldn't, because you asked for a banana, and you expect them to understand that a banana is not an orange or a fork.  It's the same principle.


#14 bluebutterflyofyourmind

bluebutterflyofyourmind
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 24 August 2008 - 02:31 AM

ah ok.  thanks for the help! 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users