imagecreatefromjpeg problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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 think I have boiled it down the the "imagecreatefromjpeg" function.
  If I comment it out I finally get an error (that relates to it being
commented out).  I have also found out that the script works fine with
smaller images (50k or so seems to work), but not with larger images
(600k or so).

It seems to be a problem with the server setup, as it works fine on my
dev server.  phpinfo() gives some standard info.  It is php 4.3.8 on

Here is the function:  If you think more of the code would be helpful
please let me know, I'll post it.

function resize_jpg($img,$img2,$w,$h){
    $imagedata = getimagesize($img);
    if ($w && ($imagedata[0] < $imagedata[1])) {
          $w = ($h / $imagedata[1]) * $imagedata[0];
    } else {
          $h = ($w / $imagedata[0]) * $imagedata[1];
    $im2 = imagecreatetruecolor($w,$h);
    $image = imagecreatefromjpeg($img); //this is the line that causes
    imagecopyresampled ($im2, $image, 0, 0, 0, 0, $w, $h, $imagedata[0],
    imagejpeg($im2, $img2, 100);

Any Ideas?


Re: imagecreatefromjpeg problem

Quoted text here. Click to load it

 OK, this points straight to memory_limit being enabled. A 600k JPEG will
decompress to several megabytes of raw image data in memory.

Quoted text here. Click to load it

 You may well have enough memory for the first image, then you run out on the

 Check what memory_limit is set to in php.ini.

 You might be able to override it to a higher value.

< Space: disk usage analysis tool

Re: imagecreatefromjpeg problem

Andy Hassall wrote:
Quoted text here. Click to load it

Thanks for the reply.  Yeah, I thought the same thing at first.
memory_limit is set to 8M according to phpinfo().  This is the same as
my dev server, so I didn't think that was the issue.

Quoted text here. Click to load it

I am making two images (for each image uploaded, im just testing with
one image though).  I tried commenting out each of them one at a time, I
get the same result.

Quoted text here. Click to load it

Ah, this is the ticket.  I didn't realy think of looking into this for
the above reasons, but I created an .htaccess file with this line:

php_value memory_limit "16M"

I can now upload, size, and thumbnail all three images.

Thanks again for your help!

Site Timeline