473,320 Members | 1,861 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,320 software developers and data experts.

GD library memory problem

Hi guys I've just tryed to upload a 1 MB image and resize it in a new
hosting (media temple) and it gives me this error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
allocate 6400 bytes) in /home/httpd/vhosts/....php

where with the GD Library a create a kind of copy:

$source = imagecreatefromjpeg($file);

Does someone know how to solve this issue?
cheers, chr
Jul 17 '05 #1
4 3971
Christian Giordano wrote:

Hi Christian,

This question is posted once every day, it seems.
(Is it in the FAQ alreadY?)
Hi guys I've just tryed to upload a 1 MB image and resize it in a new
hosting (media temple) and it gives me this error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
allocate 6400 bytes) in /home/httpd/vhosts/....php

where with the GD Library a create a kind of copy:

$source = imagecreatefromjpeg($file);

Does someone know how to solve this issue?

The problem lies in the fact that you assume that a 1 megabyte image takes
up 1 magebyte of internal memory.
This is not the case.
First the image is compressed, so if PHP needs an internal representation of
all pixels, it needs to unpack it.

A rude estimate:
If your image is 100 x 500 pixels:
that is 50.000 pixels
Every pixel needs 24 bits to store (RGB+alpha)
So you need 1.200.000 bytes (around 1.2 meg)

How to fix it?
Increase the memory that PHP can allocate (in php.ini) or work with smaller
files (if possible).

Regards,
Erwin Moller

cheers, chr

Jul 17 '05 #2
Erwin Moller wrote:

(correction)
A rude estimate:
If your image is 100 x 500 pixels:
that is 50.000 pixels
Every pixel needs 24 bits to store (RGB+alpha)
So you need 1.200.000 bytes (around 1.2 meg)
I messed up bits and bytes and math here.
sorry. :P

1 pixel needs 4 bytes (32 bits) if alpha-channel is used.

so you need 200.000 bytes for 50.000 pixel.

In your situation you exceeded the 8.000.000 bytes, so your original image
is over 2.000.000 pixels (eg 2000 x 1000 pixels)

Regards,
Erwin Moller

How to fix it?
Increase the memory that PHP can allocate (in php.ini) or work with
smaller files (if possible).

Regards,
Erwin Moller

cheers, chr


Jul 17 '05 #3
Erwin Moller wrote:
How to fix it?
Increase the memory that PHP can allocate (in php.ini) or work with
smaller files (if possible).

Regards,
Erwin Moller

cheers, chr



You can also use getimagesize() to calculate the number of pixels /
memory required before creating the bitmap--that way you can provide a
pleasant warning message to the user rather than run out of memory.

Kind regards,
Ian Fleeton
Jul 17 '05 #4
> How to fix it?
Increase the memory that PHP can allocate (in php.ini) or work with smaller
files (if possible).


thx a lot erwin! I'll pay more attention next time to search better
before posting, sorry to all!

cya, chr
Jul 17 '05 #5

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

Similar topics

4
by: M | last post by:
Hallo NG, I have problem creating automatic thumbnails from image of size 2200*1700 pixel, if I scale the same image to 1000*x pixel thumbnails creation works good. Someone knows if it's a limit...
6
by: Marco Chiarandini | last post by:
Dear all, I am experiencing a problem in the deallocation of STL data structures. In paritcular I create a vector of sets and insert integers in each set. I do not define any deallocator since...
22
by: jacob navia | last post by:
A function like strcpy takes now, two unbounded pointers. Unbounded pointers, i.e. pointers where there is no range information, have catastrophic failure modes specially when *writing* to main...
2
by: PepsiDrinker | last post by:
Hello! :^) I am trying to implement a class library for dealing with time series. I have to use time series with seasonable component and without it. Also, time series can be stored in memory or...
3
by: Giovanni Boschi | last post by:
We have found a memory leak when using a COM library with a C# application. The leak appears only if the C# application is compiled with the /optimize flag. It goes away when the C# application is...
1
by: fallleaf | last post by:
i make library, this library function is create circula-queue in shared memory and attach, queue put, queue get, etc... sample program make, 1 sample program use library, test make queue in...
11
by: Eigenvector | last post by:
I apologize if this is a trivial question, but it's always made me wonder when I have to compile my code. There are some #includes that you don't really need to reference in your library and...
20
by: Nickolai Leschov | last post by:
Hello all, I am programming an embedded controller that has a 'C' library for using its system functions (I/O, timers, all the specific devices). The supplied library has .LIB and .H files. ...
2
by: S S | last post by:
Hi I have my shared (.so) library which uses our own memory manager. 32 bit lib was working fine, but when we switched to 64 bit library, as our own defined small pointer can not handle big...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.