This is a discussion on imagecreatefromjpeg failing with lack of memory within the PHP Language forums, part of the PHP Programming Forums category; Has anyone else experience of imagecreatefromjpeg failing with an error message about memory even though the size of the image ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Has anyone else experience of imagecreatefromjpeg failing with an error
message about memory even though the size of the image being uploaded is nothing like the space available to the script? Is imagecreatefromjpeg particularly memory hungry? Immediately prior to the failure memory is given as 2405072 The jpeg being uploaded is 812201 in size Smaller jpegs work fine. jpegs created by different means all seem to fail if the size is around 500k plus. Error message is Fatal error: Allowed memory size of 16777216 bytes exhausted at (null):0 (tried to allocate 3264 bytes) in /home/virtual/site216/fst/var/www/html/mv/private/mvaddinfoinc.php on line 1997 PHP version is 4.3.3 on a shared server GD version is bundled (2.0.15 compatible) Memory limit is set to 16M Max upload is set to 16M if (function_exists('memory_get_usage')) { $mem_in_use= memory_get_usage(); } else { $mem_in_use="memory usage indeterminable"; } dev_echo("memory usage= $mem_in_use" ); $src_img = imagecreatefromjpeg("$temp_fullpicname"); if (!$src_img) { $GLOBALS[InfoMsg]->MsgAdd("Could not create image from jpeg"); unlink ( $temp_fullpicname); return false; } |
|
|||
|
Simon Stewart wrote:
> Has anyone else experience of imagecreatefromjpeg failing with an error > message about memory even though the size of the image being uploaded is > nothing like the space available to the script? > > Is imagecreatefromjpeg particularly memory hungry? > > Immediately prior to the failure memory is given as 2405072 > The jpeg being uploaded is 812201 in size > Smaller jpegs work fine. jpegs created by different means all seem to > fail if the size is around 500k plus. > > Error message is > Fatal error: Allowed memory size of 16777216 bytes exhausted at (null):0 > (tried to allocate 3264 bytes) in > /home/virtual/site216/fst/var/www/html/mv/private/mvaddinfoinc.php on line > 1997 > > PHP version is 4.3.3 on a shared server > GD version is bundled (2.0.15 compatible) > Memory limit is set to 16M > Max upload is set to 16M > > > if (function_exists('memory_get_usage')) { > $mem_in_use= memory_get_usage(); > } > else { > $mem_in_use="memory usage indeterminable"; > } > dev_echo("memory usage= $mem_in_use" ); > $src_img = imagecreatefromjpeg("$temp_fullpicname"); > if (!$src_img) { > $GLOBALS[InfoMsg]->MsgAdd("Could not create image from jpeg"); > unlink ( $temp_fullpicname); > return false; > } Hi Simon, I think you have to estimate how much memory is needed for your jpg to store it in memory with truecolor. jps is a heavily compressed format, so your 500K filesize doesn't say a lot. You need to use the pixels. (width times height) example: If your jpg is 2000X2000 pixels, that is 4.000.000 pixels. If stored truecolor you need (i think) 1 byte R 1 byte G 1 byte B 1 byte alpha channel (transparancy) So that is 4.000.000 times 4 bytes is around 16 megs. (Note: I am unsure if PHP will want to allocate all that memory when it creates an image based on a JPG. I could be possible to use only a part, but I expect PHP to want to load it all in memory.) Solution is simple: Try to increase the memory allocated to PHP in php.ini to get around this problem. Or use smaller images. Regards, Erwin Moller |
|
|||
|
Erwin
Thanks for your comments. It turns out that with around 13.5Mb free, I could upload a picture of around 2430000 pixels. This seems to be equivalent to roughly 5.5 bytes per pixel at least for the picture I was testing with. Simon Stewart. "Erwin Moller" <since_humans_read_this_I_am_spammed_too_much@spam yourself.com> wrote in message news:4125ce66$0$568$e4fe514c@news.xs4all.nl... > > Hi Simon, > > I think you have to estimate how much memory is needed for your jpg to store > it in memory with truecolor. > jps is a heavily compressed format, so your 500K filesize doesn't say a lot. > You need to use the pixels. (width times height) > > example: > If your jpg is 2000X2000 pixels, that is 4.000.000 pixels. > If stored truecolor you need (i think) > 1 byte R > 1 byte G > 1 byte B > 1 byte alpha channel (transparancy) > > So that is 4.000.000 times 4 bytes is around 16 megs. > > (Note: I am unsure if PHP will want to allocate all that memory when it > creates an image based on a JPG. I could be possible to use only a part, > but I expect PHP to want to load it all in memory.) > > Solution is simple: Try to increase the memory allocated to PHP in php.ini > to get around this problem. Or use smaller images. > > Regards, > Erwin Moller > > > |