469,328 Members | 1,275 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

imagecreatefromjpeg problem

Hi everyone,

this is one of those "inherited from someone else" projects that I'm having
problems with and was wondering if someone could help me out.

Our setup:

Redhat Linux
Apache 2.0.46
PHP 4.3.2
GD 1.8.4

We have a php-based setup that allows users to upload images and then some
back-end stuff that stores the original image and creates a thumbnail image.
I've just noticed that large images, say 1500x1500 or larger, give the
resize script some problems. We're using Shiege Iseng's resize class
(http://kentung.f2o.org/scripts/thumbnail/).

The error is coming when the class calls the imagecreatefromjpeg() function,
and the specific error is

Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to
allocate 8652 bytes) in <servername>/resize.php on line 51

The image itself is 2163x2957x24bpp at 300 dpi and is 3 megs on disk and
18.31 MB in memory, according to IrfanView.

If I use IrfanView to reduce the image to, say, 1400x1800 or so then the
resize script has no problems, so I guess there really IS a memory issue.
;-)

I'm wondering:

1. will the problem go away if I upgrade to GD 2.x?
2. will the problem go away if I upgrade to PHP 5?

It's doubtful that I'll be able to upgrade PHP or GD, though ...

So, first of all, has anyone run into a problem like this? Second, what are
my options? One big constraint is that the preferred solution is to let
users upload images to whatever size they want, so setting a 1500x1500
restriction before they upload isn't going to work.

Thanks!


Jul 17 '05 #1
5 14593
steve park wrote:


The error is coming when the class calls the imagecreatefromjpeg() function,
and the specific error is

Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to
allocate 8652 bytes) in <servername>/resize.php on line 51


Hi Steve,

You could try to get around this by adding a line like:

ini_set("memory_limit","30M");

at the top of your script.
Upgrading PHP or GD won't solve this problem. It's just a sign that the
resize script is pretty inefficient with memory. ;)
HTH.

--
http://www.phpforums.nl
Jul 17 '05 #2
On 13 Jul 2005 18:12:10 -0400, sp***@cc.gatech.edu (steve park) wrote:
We have a php-based setup that allows users to upload images and then some
back-end stuff that stores the original image and creates a thumbnail image.
I've just noticed that large images, say 1500x1500 or larger, give the
resize script some problems. We're using Shiege Iseng's resize class
(http://kentung.f2o.org/scripts/thumbnail/).

The error is coming when the class calls the imagecreatefromjpeg() function,
and the specific error is

Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to
allocate 8652 bytes) in <servername>/resize.php on line 51

The image itself is 2163x2957x24bpp at 300 dpi and is 3 megs on disk and
18.31 MB in memory, according to IrfanView.
Can you simply raise the value of memory_limit?

It's there to stop runaway scripts eating memory, but in this case you know
you need that memory for a short time to do the processing.
I'm wondering:

1. will the problem go away if I upgrade to GD 2.x?
2. will the problem go away if I upgrade to PHP 5?


Wouldn't have thought so - you're using the memory, and so memory_limit is
working as advertised.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
i had the same problem once: i got around by NOT using true color
images, which reduces the needed memory tremendously (using
imagecreate, not imagecreatetruecolor)

2 problems with that: 1st you might already be running out of memory
just opening the uploaded image and 2nd you'd have to try if the
quality is still sufficient for the thumbs.

micha

Jul 17 '05 #4
On 13 Jul 2005 18:12:10 -0400, sp***@cc.gatech.edu (steve park) wrote:
Second, what are my options?


Another option worth mentioning is running ImageMagick instead. As an external
process, it's not subject to PHP's memory limits. And it can be faster as well.

The downside is it needs you to run an external process (or load the
ImageMagick PHP extension).

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
> Another option worth mentioning is running ImageMagick instead. As an external
process, it's not subject to PHP's memory limits. And it can be faster as well.


turns out that doing something like

ini_set( "memory_limit", "200M" );

has fixed the problem.

Thanks!

steve

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Mike | last post: by
2 posts views Thread by jn | last post: by
2 posts views Thread by Simon Stewart | last post: by
1 post views Thread by Olivier | last post: by
2 posts views Thread by bernie | last post: by
6 posts views Thread by comp.lang.php | last post: by
5 posts views Thread by Areric | last post: by
4 posts views Thread by jeffsnox | last post: by
1 post views Thread by tim.landgraf | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.