imagecreatefromjpeg failing with lack of memory

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-20-2004
Simon Stewart
 
Posts: n/a
Default imagecreatefromjpeg failing with lack of memory

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


Reply With Quote
  #2 (permalink)  
Old 08-20-2004
Erwin Moller
 
Posts: n/a
Default Re: imagecreatefromjpeg failing with lack of memory

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



Reply With Quote
  #3 (permalink)  
Old 08-21-2004
Simon Stewart
 
Posts: n/a
Default Re: imagecreatefromjpeg failing with lack of memory

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
>
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:11 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0