473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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;
}
Jul 17 '05 #1
2 11025
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

Jul 17 '05 #2
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"
<si******************************************@spam yourself.com> wrote in
message news:41*********************@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

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mike | last post by:
hopefully this is an easy one to solve and I'm just missing something little... basically, I had a nice little website running with php, apache, etc... that uses imagecreatefromjpeg to create...
2
by: jn | last post by:
This is the weirdest thing I've come across in a while. I'm trying to resize an image. If I give it a small image ( < 100K) it will resize. If I give it a larger image, it gives me the IE "Action...
1
by: Olivier | last post by:
Hi, I have the following code in my php script : $fhSrc = imagecreatefromjpeg($srcFile); This cause me the following error : Fatal error: Allowed memory size of 8388608 bytes exhausted (tried...
2
by: bernie | last post by:
Howdy, I have an image upload and resize script that I have used on a number of servers with no issues. I have now use it in a new app that I uploaded to a new server. I worked fine on my dev...
6
by: comp.lang.php | last post by:
PHP version 4.3.9 GD version 2.0.2 Whenever I use imagecreatefromjpeg(), PHP completely dies. No errors, no warnings, no notices, it dies in the following manner: If using Firefox it just...
5
by: Areric | last post by:
Ok all. I have a series of images stored in a db. Im trying to work on a script that will let me scale them based on user input. Ive hit a bit of a roadblock on this line. $orig =...
4
by: jeffsnox | last post by:
Hi, I'm struggling to get imagecreatefromjpeg to work correctly. I'm running PHP 4.3.9 with GD bundled (2.0.28 compatible). If I run this: $myimage = imagecreatefromjpeg("myfilename");
1
by: tjhickey | last post by:
Hi, I've searched around the newsgroups for an answer to this but nothing seems to be helping. When trying to load an very large JPEG (about 4 meg) I was getting memory errors as you'd expect. ...
1
by: tim.landgraf | last post by:
hi there, i am experiencing a strange problem. i am iterating through a given directory, selecting only jpg - images that are then resized and inserted into a database. everything works, but if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.