473,809 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

imagecreatefrom jpeg failing with lack of memory

Has anyone else experience of imagecreatefrom jpeg 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 imagecreatefrom jpeg 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.ph p 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_exist s('memory_get_u sage')) {
$mem_in_use= memory_get_usag e();
}
else {
$mem_in_use="me mory usage indeterminable" ;
}
dev_echo("memor y usage= $mem_in_use" );
$src_img = imagecreatefrom jpeg("$temp_ful lpicname");
if (!$src_img) {
$GLOBALS[InfoMsg]->MsgAdd("Coul d not create image from jpeg");
unlink ( $temp_fullpicna me);
return false;
}
Jul 17 '05 #1
2 11052
Simon Stewart wrote:
Has anyone else experience of imagecreatefrom jpeg 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 imagecreatefrom jpeg 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.ph p 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_exist s('memory_get_u sage')) {
$mem_in_use= memory_get_usag e();
}
else {
$mem_in_use="me mory usage indeterminable" ;
}
dev_echo("memor y usage= $mem_in_use" );
$src_img = imagecreatefrom jpeg("$temp_ful lpicname");
if (!$src_img) {
$GLOBALS[InfoMsg]->MsgAdd("Coul d not create image from jpeg");
unlink ( $temp_fullpicna me);
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************ *************** *************** @spamyourself.c om> wrote in
message news:41******** *************@n ews.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
21626
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 thumbnails of larger pictures. recently, I upgraded my system from suse 8.2 to suse 9.0, so I assume my php/apache rpms were upgraded in the process...
2
4015
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 Cancelled" page. The memory_limit for PHP has been changed to 30MB so that's not the problem. I know that the line with imagecreatefromjpeg() is the problem (even though I can't get an error message). I can run this code with the large images...
1
4435
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 to allocate 4800 bytes). I read that I should increase the memory allowed php. Not sure. This script works fine on a Windows 2000/Apache/php4 machine but not
2
662
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 server, but when I submit the POST form to the page that does the resizing the page grids it gears for a while, then just quits. It is frustrating because I don't get any errors. The image does upload, but nothing seems to happen after that. I...
6
2812
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 stops running cold If using Konqueror you get the message "An error occurred while processing http://www.blah.com/tools/app"
5
3351
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 = imagecreatefromjpeg("DisplayImage.php?imageId=".$this->mImage->GetImageId()); Specifically it cant sopen that file. DisplayImage.php is pretty simple, it just displays an image from the
4
2499
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
1660
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. So I bumped the memory_limit up and I no longer get an error - NOW everything just stops. Below is a demonstration: <?
1
2954
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 there is a file with an apostrophe in it the GD function @ImageCreateFromJPEG fails. anyone knows this problem and possible workarounds? thank you, tim
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.