468,257 Members | 1,449 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

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 3800
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by M | last post: by
6 posts views Thread by Marco Chiarandini | last post: by
22 posts views Thread by jacob navia | last post: by
2 posts views Thread by PepsiDrinker | last post: by
3 posts views Thread by Giovanni Boschi | last post: by
1 post views Thread by fallleaf | last post: by
11 posts views Thread by Eigenvector | last post: by
2 posts views Thread by S S | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.