472,804 Members | 768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 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 3946
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.